Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81684

New Button Invert Selection Code

$
0
0
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 ;).

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);
            }
        }]
    }
});

Viewing all articles
Browse latest Browse all 81684

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>