Using row-selector function to do work instead of select rows

Using row-selector function to do work instead of select rows

LaxCrosse007LaxCrosse007 Posts: 2Questions: 0Answers: 0

I am not having a problem but rather curiosity relating to performance.

I have a situation where I need to check every row in my table after it initializes for a criteria, and then if this criteria is true, run a function on it (applying jqueryUI.draggable to it). The criteria is simple, whether a particular column in the table has a 1 or a 0.

On my first attempt, I used a selector function to check whether this column was a 1 or a 0, and did a return true : false appropriately, and chained onto that an "every(function())" to apply the logic. Essentially:

dataTable.rows( function (idx, data, node) {
     return data.Criteria == 0 ? true : false
}).every( function() {
     applyDraggableToRow(this.nodes().to$(), dataTable.cell(this,'ID:name').data());
});

My function applyDraggableToRow requires data from the ID column of the row. This worked well, with acceptable performance, but I wanted to see if I could do better. So I refactored it like so:

dataTable.rows( function(idx, data, node) {
       if (data.Criteria == 0)  applyDraggableToRow($(node), data.ID);
});

I found this second method worked as well, and gave me a roughly 5x performance improvement.

I couldn't find any posts or information relating to using the row-selector function in this way, so I am just curious if there is a downside I am missing to this approach.

This discussion has been closed.