Home › Forums › Guriddo jqGrid JS › Selecting All Rows From Every Page
Tagged: Select Rows
With the multiselect function, it only selects the rows on the current page. Is there a way to select all rows from all the pages at once?
Hello,
Yes there is way to do this. It uses some not documented grid property _index, which hold all the id of the grid in case the datatype is local.
Suppose you want to do this on button click, the code is:
|
1 2 3 |
$("#button").click(function(){ // wrong code. See below }); |
Kind Regards,
Will
Guriddo Support Team
Hello,
Sorry the first code is wrong the correct code is:
|
1 2 3 4 5 6 7 8 9 |
$("#ddd").click(function(){ var indexes = $("#jqGrid").jqGrid('getGridParam','_index'); var arr=[]; for(var key in indexes) { $("#jqGrid").jqGrid('setSelection',key, true); arr.push(key); } $("#jqGrid").jqGrid('setGridParam',{ 'selarrrow' : arr}); }); |
Guriddo Support Team
It doesn’t seem to work, as it results in 0 rows being selected. Am I missing something? Here is an example using the one from the guriddo sitem using a button “btnSelect”:
<!DOCTYPE html>
<html lang=”en”>
<head>
<script type=”text/ecmascript” src=”http://www.guriddo.net/demo/js/jquery.min.js”></script>
<script type=”text/ecmascript” src=”http://www.guriddo.net/demo/js/trirand/i18n/grid.locale-en.js”></script>
<script type=”text/ecmascript” src=”http://www.guriddo.net/demo/js/trirand/jquery.jqGrid.min.js”></script>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”http://www.guriddo.net/demo/css/jquery-ui.css” />
<!– The link to the CSS that the grid needs –>
<link rel=”stylesheet” type=”text/css” media=”screen” href=”http://www.guriddo.net/demo/css/trirand/ui.jqgrid.css” />
<meta charset=”utf-8″ />
<title>jqGrid Loading Data – Million Rows from a REST service</title>
</head>
<body>
<table id=”jqGrid”></table>
<script type=”text/javascript”>
$(document).ready(function() {
$(“#jqGrid”).jqGrid({
url: ‘http://trirand.com/blog/phpjqgrid/examples/jsonp/getjsonp.php?callback=?&qwery=longorders’,
mtype: “GET”,
datatype: “jsonp”,
colModel: [{
label: ‘OrderID’,
name: ‘OrderID’,
key: true,
width: 75
},
{
label: ‘Customer ID’,
name: ‘CustomerID’,
width: 150
},
{
label: ‘Order Date’,
name: ‘OrderDate’,
width: 150,
formatter: ‘date’,
formatoptions: {
srcformat: ‘Y-m-d H:i:s’,
newformat: ‘ShortDate’
}
},
{
label: ‘Freight’,
name: ‘Freight’,
width: 150
},
{
label: ‘Ship Name’,
name: ‘ShipName’,
width: 150
}
],
viewrecords: true,
width: 780,
height: 250,
multiselect: true,
rowNum: 20,
pager: jqGridPager
});
$(“#btnSelect”).click(function(){
var indexes = $(“#jqGrid”).jqGrid(‘getGridParam’,’_index’);
var arr=[];
for(var key in indexes) {
$(“#jqGrid”).jqGrid(‘setSelection’,key, true);
arr.push(key);
}
$(“#jqGrid”).jqGrid(‘setGridParam’,{ ‘selarrrow’ : arr});
var selectedIDs = $(“#jqGrid”).getGridParam(“selarrrow”);
alert(selectedIDs.length);
});
});
</script>
<input id=”btnSelect” class=”btn btn-default” type=”button” value=”Select All Rows” />
</body>
</html>
Hello,
As I explain in my first post the above code is valid only if datatype is local – this mean that all the data is available at client side.
Your data is json and hence it comes from the server – this means that at client there is no local data.
To explain simple – your data comes from the server at portions (pages). In the grid we store only the current page.
We know the id of the rows in the current page only and we do not know all other id’s, since they are at server and we can not select them.
I hope you understand the diffrence.
If you explain us what is your goal and why you need all the ids of the rows, maybe we can recommend you a solution.
Kind Regards,
Will
Guriddo Support Team
Sorry, I missed that local datatype detail. I understand now, thank you. What I wanted was to select all rows with the multiselect. What I did to solve this issue was to add an “All” option to the pager count dropdown, so user can show all rows in grid, then perform the select all.
Hello,
Thank you for the response.
Glad to hear, that you have find a solution of the problem.
Kind Regards
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top