Conditional formatting

The following example demonstrates how to use the cell type renderer feature to make some conditional formatting: first row is read-only and formatted in green boldtext; empty cells have greybackground; negative numbers are written in red. First column has the same styling as first row, but cells are editable. All colors and other styles can be set in table configuration.

KiaNissanToyotaHondaMazdaFord
2003-382933884932353-47758Read only
20042343388569488921232227840
200564393-89432Read only8939042853-12228
20064538257729-48823-12774-98493
2007-8643348923-33378Read only9004334982
200845833-12293128947885943054
2009Read only49950-58823-5788289954
2010-8594390449-388823492823487
201144950-90092Read only89003Read only
201223486Read only4772923945-9900148995
201390392488521778932984
2014-473828845758875-45398
Sorting data

If you want to sort data in your datasource array, you can simply invoke an Array.prototype.sort()function and call render()function to refresh the table. You don't need any plugin for this. However, this operations alters the structure of the datasource, and in many cases you want to leave the datasource intact, while displaying its content in a specified order. Here's where column sorting plugin comes in handy.

 
A
B
C
D
E
F
1
1George Washingtonhttp://en.wikipedia.org/wiki/George_Washington30/04/17894/03/1797Virginia
2
2John Adamshttp://en.wikipedia.org/wiki/John_Adams4/03/17974/03/1801Massachusetts
3
3Thomas Jeffersonhttp://en.wikipedia.org/wiki/Thomas_Jefferson4/03/18014/03/1809Virginia
4
4James Madisonhttp://en.wikipedia.org/wiki/James_Madison4/03/18094/03/1817Virginia
5
5James Monroehttp://en.wikipedia.org/wiki/James_Monroe4/03/18174/03/1825Virginia
6
6John Quincy Adamshttp://en.wikipedia.org/wiki/John_Quincy_Adams4/03/18254/03/1829Massachusetts
7
7Andrew Jacksonhttp://en.wikipedia.org/wiki/Andrew_Jackson4/03/18294/03/1837Tennessee
8
8Martin Van Burenhttp://en.wikipedia.org/wiki/Martin_Van_Buren4/03/18374/03/1841New York
9
9William Henry Harrisonhttp://en.wikipedia.org/wiki/William_Henry_Harrison4/03/18414/04/1841Ohio
10
10John Tylerhttp://en.wikipedia.org/wiki/John_Tyler4/04/18414/03/1845Virginia
11
11James K. Polkhttp://en.wikipedia.org/wiki/James_K._Polk4/03/18454/03/1849Tennessee
12
12Zachary Taylorhttp://en.wikipedia.org/wiki/Zachary_Taylor4/03/18499/07/1850Louisiana
 
A
B
C
D
E
F
 
1
2
3
4
5
6
7
8
9
10
11
12
 
Pagination

The following example demonstrates optional pagination feature. Data arrays are divided into parts, it could be also virtual split - calculating start and stop of each page. Pagination feature uses standard Bootstrap paginationcomponent which is connected to hash links. A small piece of jQuery code switches activeclass depending on the hash change.

A
B
C
D
E
F
1George Washingtonhttp://en.wikipedia.org/wiki/George_Washington30/04/17894/03/1797Virginia
2John Adamshttp://en.wikipedia.org/wiki/John_Adams4/03/17974/03/1801Massachusetts
3Thomas Jeffersonhttp://en.wikipedia.org/wiki/Thomas_Jefferson4/03/18014/03/1809Virginia
4James Madisonhttp://en.wikipedia.org/wiki/James_Madison4/03/18094/03/1817Virginia
5James Monroehttp://en.wikipedia.org/wiki/James_Monroe4/03/18174/03/1825Virginia
6John Quincy Adamshttp://en.wikipedia.org/wiki/John_Quincy_Adams4/03/18254/03/1829Massachusetts
7Andrew Jacksonhttp://en.wikipedia.org/wiki/Andrew_Jackson4/03/18294/03/1837Tennessee
8Martin Van Burenhttp://en.wikipedia.org/wiki/Martin_Van_Buren4/03/18374/03/1841New York
9William Henry Harrisonhttp://en.wikipedia.org/wiki/William_Henry_Harrison4/03/18414/04/1841Ohio
10John Tylerhttp://en.wikipedia.org/wiki/John_Tyler4/04/18414/03/1845Virginia
A
B
C
D
E
F
Pre-populating new rows

The following example demonstrates how cell renderers can be used to present the template values for empty rows. When any cell in the empty row is edited, the onChangecallback fills the row with the template values. It uses a set of arrays as a template, so empty cells text can be either empty or with any custom text.

A
B
C
D
E
F
1George Washingtonhttp://en.wikipedia.org/wiki/George_Washington30/04/17894/03/1797Virginia
2John Adamshttp://en.wikipedia.org/wiki/John_Adams4/03/17974/03/1801Massachusetts
3Thomas Jeffersonhttp://en.wikipedia.org/wiki/Thomas_Jefferson4/03/18014/03/1809Virginia
4James Madisonhttp://en.wikipedia.org/wiki/James_Madison4/03/18094/03/1817Virginia
5James Monroehttp://en.wikipedia.org/wiki/James_Monroe4/03/18174/03/1825Virginia
6John Quincy Adamshttp://en.wikipedia.org/wiki/John_Quincy_Adams4/03/18254/03/1829Massachusetts
7Andrew Jacksonhttp://en.wikipedia.org/wiki/Andrew_Jackson4/03/18294/03/1837Tennessee
8Martin Van Burenhttp://en.wikipedia.org/wiki/Martin_Van_Buren4/03/18374/03/1841New York
9William Henry Harrisonhttp://en.wikipedia.org/wiki/William_Henry_Harrison4/03/18414/04/1841Ohio
10John Tylerhttp://en.wikipedia.org/wiki/John_Tyler4/04/18414/03/1845Virginia
11James K. Polkhttp://en.wikipedia.org/wiki/James_K._Polk4/03/18454/03/1849Tennessee
12Zachary Taylorhttp://en.wikipedia.org/wiki/Zachary_Taylor4/03/18499/07/1850Louisiana
onetwothreefourfivesix
A
B
C
D
E
F
Highlighting current

The following example demonstrates an ability to highlight current column and row with specified background color, attached to activeclass. This can be achieved with simple usage of currentRowClassNameand currentColClassNameoptions added to the table configuration. Please note - you can add any class, default class name which has been implemented in CSS is .active.

 
A
B
C
D
E
F
1
1George Washingtonhttp://en.wikipedia.org/wiki/George_Washington30/04/17894/03/1797Virginia
2
2John Adamshttp://en.wikipedia.org/wiki/John_Adams4/03/17974/03/1801Massachusetts
3
3Thomas Jeffersonhttp://en.wikipedia.org/wiki/Thomas_Jefferson4/03/18014/03/1809Virginia
4
4James Madisonhttp://en.wikipedia.org/wiki/James_Madison4/03/18094/03/1817Virginia
5
5James Monroehttp://en.wikipedia.org/wiki/James_Monroe4/03/18174/03/1825Virginia
6
6John Quincy Adamshttp://en.wikipedia.org/wiki/John_Quincy_Adams4/03/18254/03/1829Massachusetts
7
7Andrew Jacksonhttp://en.wikipedia.org/wiki/Andrew_Jackson4/03/18294/03/1837Tennessee
8
8Martin Van Burenhttp://en.wikipedia.org/wiki/Martin_Van_Buren4/03/18374/03/1841New York
9
9William Henry Harrisonhttp://en.wikipedia.org/wiki/William_Henry_Harrison4/03/18414/04/1841Ohio
10
10John Tylerhttp://en.wikipedia.org/wiki/John_Tyler4/04/18414/03/1845Virginia
11
11James K. Polkhttp://en.wikipedia.org/wiki/James_K._Polk4/03/18454/03/1849Tennessee
12
12Zachary Taylorhttp://en.wikipedia.org/wiki/Zachary_Taylor4/03/18499/07/1850Louisiana
 
A
B
C
D
E
F
 
1
2
3
4
5
6
7
8
9
10
11
12