Reputation: 3693
I am working with a rails app. and I am using jqgrid for my html responces. I need to export selected rows (using checkboxes displayed in grid). I used rails fastercsv lib to extract data in .csv but it is exporting all the rows which is displayed on the page. How can I make use of the checkboxes available on the grid to export only selected rows??
I am new to rails and jqgrid so any reply would be appreciated.
Thanx
Upvotes: 0
Views: 1086
Reputation: 3693
from line 24-44. Need to make async:false means synchronous ajax call is the solution.
Upvotes: 0
Reputation: 1758
This is how you can get the selected rows from jqgrid.
var selRowIds = grid.jqGrid('getGridParam', 'selarrrow');
if(selRowIds.length>0)
{
for( var i=0;i<selRowIds.length;i++){
var Name=getCellValue(selRowIds[i],'Name');
var Company=getCellValue(selRowIds[i],'Company');
$.ajax({
type: 'POST',
url: '@Url.Action("ExportToCSV")',
contentType: 'application/json; charset=utf-8',
data:JSON.stringify({Name:Name,Company:Company}),
dataType: "json",
success:function(){
grid.trigger("reloadGrid");
}
});
}
}
Now i'll explain how this code works. I'm using multiselect:true in my jqgrid parameters so i can get my checkboxes with each row. Now if i check 5 rows, they will be selected and i can get their row ids using selarrow, like the way I'm doing in my code and then lets suppose you have Name and Company in your jqgrid columns then i can get their values like i'm doing in my code and then you can make ajax request using jquery to server method(exportToCSV) which in your case will be in ruby-rails.
Upvotes: 1