Can I use fnServerParams inside of oTableTools for jquery datatables?

Can I use fnServerParams inside of oTableTools for jquery datatables?

ScrumGuy000ScrumGuy000 Posts: 2Questions: 0Answers: 0
edited November 2012 in TableTools
I need to pass in an ID to initialize a jquery datatable. I'm using fnServerParams correctly in the main table, but when I click on the export button, the ID I need is no longer in the param parameter passed to the controller. Do I need to do something inside of oTableTools to retrieve the ID?

Javascript:

$(document).ready(function () {
var oTable = $('#tblAddressErrors').dataTable({
"bJQueryUI": true,
"iDisplayLength": 25,
"bServerSide": true,
"sAjaxSource": "/Issuance/Issuance/AjaxHandler2",
"sScrollX": "100%",
"bProcessing": true,
"aoColumns": [
{ "sName": "Master_Name" },
{ "sName": "Group_Name" },
{ "sName": "household_id",
"fnRender": function (oObj) {
var householdId = oObj.aData[2];
return '' + householdId + '';
},
"bUseRendered": false
},
{ "sName": "First_Name" },
{ "sName": "Last_Name" },
{ "sName": "Pan_NR" }
],
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "/Content/media/swf/copy_csv_xls.swf",
"aButtons": [{ "sExtends": "download", "sButtonText": "Export", "sUrl": "/Issuance/Issuance/AjaxHandlerExport2" }]
},
"fnServerParams": function (aoData) {
aoData.push(
{ "name": "cardStockId", "value": $("#CardStockId").val() }
);
}
});
});

Controller Actions:

public ActionResult AjaxHandlerExport2(JQueryDataTableParamModel param)
{
var addressErrorsExports = (from addressErrorExport in GetAddressErrors(param, true).Issuances
select new
{
MasterGroupName = addressErrorExport.Group.MasterGroupName,
GroupName = addressErrorExport.Group.Name,
HouseholdID = addressErrorExport.HouseholdId,
FirstName = addressErrorExport.Group.ContactInfo.FirstName,
LastName = addressErrorExport.Group.ContactInfo.LastName,
PAN = addressErrorExport.PanNumber.ToString()
}).ToList();

return File(addressErrorsExports.ExportToCsv(new string[0]), "application/ms-excel", "AddressErrors.xls");
}

private IssuanceResults GetAddressErrors(JQueryDataTableParamModel param, bool isExport)
{
IssuanceResults issuanceResults = new IssuanceResults();
IssuanceSearch issuanceSearch = PopulateIssuanceSearch(param, isExport);
issuanceSearch.CardStockId = param.cardStockId;

using (var householdService = _householdService.GetWrappedProxy())
{
issuanceResults = householdService.BaseObject.GetIssuanceResults(issuanceSearch, Common.Issuance.ReturnType.AddressErrors);
}
return issuanceResults;
}

private IssuanceSearch PopulateAddressErrors(JQueryDataTableParamModel param, bool isExport)
{
return new IssuanceSearch
{
Text = param.sSearch ?? string.Empty,
MaxRows = isExport ? Properties.Settings.Default.MaxExportRows : param.iDisplayLength,
RowIndex = isExport ? 0 : param.iDisplayStart,
SortColumn = param.sColumns.Split(',')[param.iSortCol_0],
SortDirection = param.sSortDir_0,
};
}

So basically, when I hit the GetAddressErrors method the first time, when the table is first initialized CardStockID is populated, however when I click on the Export button on the jquery datatable and hit the GetAddressErrors method again, CardStockID is no longer populated in the param.

Replies

This discussion has been closed.