distinguish between init draws and search draw
distinguish between init draws and search draw
Nevo
Posts: 3Questions: 1Answers: 0
Hi All,
Im using the draw() event and want to know if there is a way dto distinguish between draw types.
For example, init draw will be used to build a select element but a search draw only to filter row results without re-build the select element options.
//Init draw
$table.on('draw.dt', function (e) {
var results = $table
.column( $index )
.data()
.unique();
//build the select element
})
//Search draw
$table.on('draw.dt', function (e) {
//Do search stuff
})
Thank you,
Nevo
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Answers
Use
init
for the first build.Allan
Thank you Allan,
The init function will not be a good option in my case as it fires when the table complete construct.
The rows are added later (after filtering).
So the sequence is table construct -> rows draw.
Thats why i wanted to find a way to distinguish between the two.
Is there a way to pass a variable with the draw?
something like: .draw('init') and .draw('reload')?
Thanks,
Nevo
When you say init you mean when new rows are initially added to the table, right? In this case there is nothing to pass into the
draw
event to note if the draw is a result of adding rows.One option might be to use a global variable as a flag. Set it true when you add the rows. In the
draw
event check the flag, if true rebuild the select lists. At the end of thedraw
function always set the flag false.Kevin
Thank you Kevin,
I thought about such solution but hoping to avoid more maintenance.
Nevo.