I'm a newbie to JQuery.
I'm trying to use the function listed here.
The mya=$("#list").getDataIDs(); // Get All IDs
is listing the IDs that are only in the current view. However my grid is paginated one. How can I fetch all the IDs?
Here is my code:
$(document).ready(function () {
jQuery("#customer_list").jqGrid({
url:'jq_customer_list',
datatype: "json",
colNames:['Col1','Col2','Col3'],
colModel:[
{name:'Col1',index:'Col1', width:100},
{name:'Col2',index:'Col2', width:80},
{name:'Col3',index:'Col3', width:75},
],
rowNum:20,
rowList:[5,10,20],
mtype:"GET",
rownumber:true,
rownumWidth:40,
pager: $("#customer_list_pager"),
viewrecords: true,
gridview: true,
caption:"My Data",
height: '50%',
pagination:true
}).navGrid('#customer_list_pager', { search:true, del: false, add: false, edit: false,searchtext:"Search" },
{}, // default settings for edit
{}, // default settings for add
{}, // delete
{closeOnEscape: true, multipleSearch: true,
closeAfterSearch: true }, // search options
{}
).navButtonAdd('#customer_list_pager',{
caption:"Export to Excel",
buttonicon:"ui-icon-save",
onClickButton: function(){
exportExcel($(this));
},
position:"last"
});
function exportExcel($id){
alert('excelExport');
var keys=[], ii=0, rows="";
var ids=$id.getRowData(); // Get All IDs
var row=$id.getRowData(ids[0]); // Get First row to get the labels
for (var k in row) {
keys[ii++]=k; // capture col names
rows=rows+k+"\t"; // output each Column as tab delimited
}
rows=rows+"\n"; // Output header with end of line
for(i=0;i<ids.length;i++) {
row=$id.getRowData(ids[i]); // get each row
for(j=0;j<keys.length;j++) rows=rows+row[keys[j]]+"\t"; // output each Row as tab delimited
rows=rows+"\n"; // output each row with end of line
}
rows=rows+"\n"; // end of line at the end
var form = "<form name='csvexportform' action='excelExport' method='post'>";
form = form + "<input type='hidden' name='csvBuffer' value='"+rows+"'>";
form = form + "</form><script>document.csvexportform.submit();</sc"+"ript>";
OpenWindow=window.open('', '');
OpenWindow.document.write(form);
OpenWindow.document.close();
}
$("#customer_list").filterToolbar({autosearch:true });
});