New Button Invert Selection Code

New Button Invert Selection Code

shazadashazada Posts: 1Questions: 0Answers: 0
edited October 2012 in TableTools
Hi,

I didn't see any topic with the inverted selection button, hence I took my time to write it.

The following works for my need and hopefully someone can add it to the stock code, because what's great can be greater ;).

[code]
var oTable = $('#example').dataTable({
"sDom": 'T<"clear">lfrtip',
"oTableTools": {
"sRowSelect": "multi",
"aButtons": ["select_all", "select_none",
{
"sExtends": "text",
"sButtonText": "Invert Selection",
"fnClick": function(nButton, oConfig) {
var selected = [];
var unselected = [];
var data = this.s.dt.aoData;

for (var i = 0; i < data.length; i++) {
if (data[i]._DTTT_selected)
selected.push(data[i]);
else
unselected.push(data[i]);
}
this._fnRowDeselect(selected);
this._fnRowSelect(unselected);
}
}]
}
});
[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Nice one - thanks for sharing this with us!

    Regards,
    Allan
This discussion has been closed.