php - JQgrid how do I change background color of row based on server data? -
i'm trying change background color of multiple rows based on data returned sql query. i'm using json data type , have tried using loadcomplete iterate through grid , color rows adding css class after grid loaded. works have 1000's of rows returned , method slows down loading of grid. user has wait long time before grid loaded.
i haven't tried using customer formatter color rows because i'm told grid not available yet when customer formatter triggered there error? have seen documentation on setting timeout period grid available in dom customer formatter sounds slow loading of grid i'm trying avoid.
ideally assign class row during server call (php) based on table data , when grid loaded on client side colors row based on css style. seems assigning class on server side efficient way don't have cycle through data more once or draw grid more once? other techniques available doing this? thanks!
the best way want use rowattr
. described in the answer need. in more old versions have iterate it's described in more old answer , set class rows.
the important understand every change of 1 elements on page follows recalculating of position of all other elements existing on page. minimum need done reflow (see here). in case of usage gridview: true
option of jqgrid all rows of grid body created string first , placed on page one operation (something assign innerhtml
property). improve performance dramatically in case of usage large number of rows without paging. if use custom formatter, cellattr
or rowattr
can customize default process of building of grid body without performance disadvantages.
the usage of custom formatter correct in general, problem have defines formatter every column. if want use many columns of different types (checkboxes, numbers, currency) usage of custom formatter not good, because have implement 1 more time formatters or call predefined formatters custom formattres, make unneeded code.
the usage of cellattr
better (see here, here or here) have set class
attribute of all cells (columns) instead of setting class
attribute of rows (<tr>
).
so find best use rowattr
suggested @ beginning of answer. in the answer find need.
Comments
Post a Comment