Reputation: 598
I am trying to get list of all un-selected row index in jqwidgets grid. As there is a predefined method to get list of all selected row index:
var allSelectedVals=[];
var rowindexes = jQuery('#userProfiles').jqxGrid('getselectedrowindexes');
for (var i = 0; i < rowindexes.length; i++)
{
var data = jQuery('#userProfiles').jqxGrid('getrowdata', rowindexes[i]);
allSelectedVals.push(data.userId);
}
alert('allSelectedVals: ' + allSelectedVals);
Is there any similar approach for getting un-selected row index also?
I will appreciate all your help to get it. Thanks in advance
Upvotes: 1
Views: 1856
Reputation: 2297
The "getboundrows" method of jQWidgets Grid returns all rows - Example:
var data = generatedata(5);
var source = {
localdata: data,
datafields: [{
name: 'firstname',
type: 'string'
}, {
name: 'lastname',
type: 'string'
}, {
name: 'productname',
type: 'string'
}, {
name: 'date',
type: 'date'
}, {
name: 'quantity',
type: 'number'
}, {
name: 'price',
type: 'number'
}],
datatype: "array"
};
var adapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid({
width: 600,
height: 100,
theme: 'energyblue',
source: adapter,
sortable: true,
selectionmode: 'singlecell',
columns: [{
text: 'First Name',
datafield: 'firstname',
columngroup: 'Name',
width: 90
}, {
text: 'Last Name',
columngroup: 'Name',
datafield: 'lastname',
width: 90
}, {
text: 'Product',
datafield: 'productname',
width: 170
}, {
text: 'Order Date',
datafield: 'date',
width: 160,
cellsformat: 'dd-MMMM-yyyy'
}, {
text: 'Quantity',
datafield: 'quantity',
width: 80,
cellsalign: 'right'
}, {
text: 'Unit Price',
datafield: 'price',
cellsalign: 'right',
cellsformat: 'c2'
}]
});
$("#jqxbutton").jqxButton({
theme: 'energyblue',
width: 200,
height: 30
});
$('#jqxbutton').click(function () {
var rows = $('#jqxgrid').jqxGrid('getboundrows');
var result = "";
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
result += row.firstname + " " + row.lastname + " " + row.productname + " " + row.date + " " + row.quantity + " " + row.price + "\n";
}
alert(result);
});
http://jsfiddle.net/jqwidgets/3LLVW/. Having the indexes of the selected rows, you can loop through the rows and check whether the row's boundindex is within the rowIndexes Array. If it's not, then the row is not selected.
Example: http://jsfiddle.net/jqwidgets/yzqswcvr/
Upvotes: 1
Reputation: 7695
There is not built-in method for this purpose, so I've wrote simple possible function here it is: we get total row count, and removing all ids from selected items (selected items are calculated upon selection, not when calling this method, thus does not take any meaning effort).
Here is the method:
function getUnselectedIndexes(selector)
{
var selectedIndexes = $(selector).jqxGrid('getselectedrowindexes');
var meta = $(selector).jqxGrid('getdatainformation');
var total = meta.rowscount;
var unSelectedIndexes = new Array();
for (i = 0; i < total; i++)
{
if (selectedIndexes.indexOf(i) !== -1)
{
continue;
}
unSelectedIndexes.push(i);
}
console.log(unSelectedIndexes);
return unSelectedIndexies;
}
And you can get all unselected indexes by calling it this way:
getUnselectedIndexes("#userProfiles");
Upvotes: 2