Forum


17:36

07/10/2014

Hi,
   i have a jqgrid which populates data form database.when i click on name header to search particular name and press enter it will give only those records with the searched name.now i want to export to excel that filter names.while exporting its giving all the rows in the grid not the filter records which i searched with particular name not sure where i am doing wrong.
here is my code..
$("#list").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: true, defaultSearch: "cn" }).navButtonAdd('#pager', {caption:"Export to Excel",
buttonicon:"ui-icon-disk",
onClickButton:function() {
ExportDataToExcel("#list");
},
position:"last"
});
Â
function ExportDataToExcel(tableCtrl) {
ExportJQGridDataToExcel(tableCtrl,"View.xlsx");
}
Â
function ExportJQGridDataToExcel(tableCtrl, excelFilename) {
  Â
   var allJQGridData = $(tableCtrl).jqGrid('getGridParam', 'data');
   var jqgridRowIDs = $(tableCtrl).getDataIDs();             Â
   var headerData = $(tableCtrl).getRowData(jqgridRowIDs[0]);  // Fetch the list of "name" values in our colModel
Â
   var columnNames = new Array();     Â
   var columnHeaders = new Array();   Â
   var inx = 0;
   var allColumnNames = $(tableCtrl).jqGrid('getGridParam', 'colNames').slice();
   allColumnNames.splice(0, 1);
   for (var headerValue in headerData) {
     Â
       var isColumnHidden = $(tableCtrl).jqGrid("getColProp", headerValue).hidden;
       if (!isColumnHidden && headerValue != null) {
           columnNames.push(headerValue);
           columnHeaders.push(allColumnNames[inx]);
       }
       inx++;
   }
 Â
   var excelData = '';
   for (var k = 0; k < columnNames.length; k++) {
       excelData += columnHeaders[k] + "\t";
   }
   excelData = removeLastChar(excelData) + "
";
Â
   var cellValue = '';
   for (i = 0; i < allJQGridData.length; i++) {
       var data = allJQGridData[i];
       for (var j = 0; j < columnNames.length; j++) {
         Â
           cellValue = '' + data[columnNames[j]];
           if (cellValue == null)
               excelData += "\t";
           else {
               if (cellValue.indexOf("a href") > -1) {
                Â
                   cellValue = $(cellValue).text();
               }
              Â
               cellValue = cellValue.replace(/'/g, "'");
               excelData += cellValue + "\t";
           }
       }
       excelData = removeLastChar(excelData) + "
";
   }
Â
   postAndRedirect("Helpers/ExportGridToExcel.ashx?filename=" + excelFilename, { excelData: excelData });
}
17:20

Moderators
30/10/2007

Hello,
Â
This is know problem.
Unfortunately this is not supported at the moment.Â
You can use the build-in manipulating with local data in grid, but I think it is a little bit complex.
Â
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
10 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66