ColVis and stateSave
ColVis and stateSave
trongart
Posts: 222Questions: 51Answers: 0
In this test case, certain cells of the Extn column are set to have a green background as set in createdRow
. Everything is correct when the table loads. However, if I hide the Extn column and reload the table without it (state is saved with stateSave) and then unhide the Extn column, the same cells no longer have the green background.
Is there a way for stateSave to keep the setting from createdRow
?
This question has accepted answers - jump to:
Answers
Is there maybe a way to run the
createdRow
function every time a column is unhidden with ColVis:The
rowCallback
will run each time the row is drawn versusoption createdRow
which runs only once when the row is created. Use thecolumn-visibility
to executedraw()
to forcerowCallback
to run. See this example:http://live.datatables.net/pusoquju/7/edit
Kevin
@kthorngren Thank you so much for your help with this!
I have to use
createdRow
instead ofrowCallback
as the latter drains performance considerably especially for large tables and data. Is there maybe a way to keepcreatedRow
in the initial table code and to runrowCallback
only within thecolumn-visibility
event?Or alternatively, is it possible to run the specific setting
if(data['extn']>=5000){
$(row).find('.data3').css('background-color', 'rgb(204, 255, 204)');
}
within
column-visibility
event?I think you can use
rows().every()
with theselector-modifier
of{ page: "current" }
to loop the rows on the page. Instead ofvar data = this.data();
, as shown in the examples, usevar node = this.node();
to get therow().node()
.Kevin
@kthorngren Thank you for this suggestion! I applied
rows().every()
with node and theselector-modifier
in this test case, but the same problem still occurrs: live.datatables.net/jocixaru/1/edit.Not sure if I've done this right:
Would I need to run this inside
rows().every()
?Or can it rerun
createdRow
?The
createdRow
runs only once when the row is created. There is nothing to force it to run again.See if this example does what you want:
http://live.datatables.net/vesadezu/1/edit
The
{ page: "current" }
is used withroes().every()
. Pasted your above code snippet into the loop and changed$(row)
to$(node)
.Kevin
Kevin, appreciate your help- This works well and I applied the code analogously into my project by adding
table.on( 'column-visibility.dt',...
.However, the performance drain is the same as using
rowCallback
instead ofcreatedRow
for some reason.How is this possible when
rows().every()
only gets accessed after ColVis button click? If not, is there a way to limitrows().every()
only totable.on( 'column-visibility.dt',...
?Guess I don't understand the question. The
rows().every()
is in thecolumn-visibility
event and should only run when the column visibility changes. The rows thatrows().every()
loops are those displayed on the page with{ page: "current" }
. How many rows do you have on the page?I don't believe the
table.draw()
is needed. It was used to runrowCallback
.Kevin
Removing
table.draw()
was the solution! Thank you so much!!