rowCallback not being called on update
rowCallback not being called on update
Hi, I'm trying to update a particular column using row.every()
and apply custom styles, but it seems rowCallback
is not called on update. Is it because rows are not being drawn and only data is updated? In such case, how should I update the data/column or apply custom styles? Moreover, I'm not really fan of using rowCallback
due to its inefficiency (on large datasets), but I couldn't find any other ways to achieve the behavior I want. How do I proceed on this?
This question has an accepted answers - jump to answer
Answers
If it is every row in a particular column that you would like to update you don't really need "rowCallback" in my opinion.
"columnDefs" could really help you. Like in this example from my own coding:
The first one is obvious. I assign class "hiddenCols" to <th> elements in my HTML and they are hidden right away. That makes it dynamic when changes are made.
The second and third ones are more interesting: Based on the class of the <th> element in your HTML you can assign a class to every cell (<td>) of the respective column.
With "text-center" I apply a bootstrap class to every cell of the column. Just replace this with a class that has your custom styles and you should be done. I need "noSelect" to make sure the selector for column visibility is dynamic, too.
One more thing: Using row.every() inside rowCallback mostly isn't very effective: rowCallback is called for every row anyway. Looping through all of the rows for every row is a lot of looping ...
Hey rf1234, thanks for taking your time answering the question.
Yes, I've already tried using
columnDefs
but the problem is I need to apply classes/styles based on certain conditions. So that didn't help. Unless it's possible to apply classes throughrender
that I'm not aware of?Also, I'm not calling
row.every()
insiderowCallback
. It's just that after the update usingrow.every()
, 'rowCallback' isn't fired. Thanks for your concern thorowCallback
will be called for every row, when the table is drawn. Updating a row doesn’t automatically redraw the table - you need to calldraw()
.Perhaps you can show us your code?
Allan
Hi @allan
draw()
did the trick. Thanks!On a second thought, is it possible to fire
createdRow
usingdraw()
or any other method (w/o completely resetting the table)? Or, apply conditional classes/styles viacolumnDefs.render()
?nevermind. figured.
createdRow
is called only once when the row is created. Its not called again.rowCallback
is basically the same except it runs each time the table is drawn.columns.render
is not meant for applying styles to dom elements as the element might not by in the dom whencolumns.render
runs.Just curious why you are asking about alternatives to
rowCallback
. If you are updating the data that might affect the row styling thenrowCallback
is the callback to use.Kevin