我可以在oTableTools中使用fnServerParams来获取jquery数据表吗?

时间:2012-11-20 20:27:39

标签: jquery asp.net-mvc datatables

我需要传入一个ID来初始化一个jquery数据表。我正在主表中正确使用fnServerParams,但是当我单击导出按钮时,我需要的ID不再是传递给控制器​​的param参数。我是否需要在oTableTools中执行某些操作来检索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 '<a href=\"/Household/Household/Details?householdId=' + householdId + '\">' + householdId + '</a>';
                            },
                            "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() }
            );
        }
    });
});

控制器操作:

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,
            };
        }

所以基本上,当我第一次点击GetAddressErrors方法时,首次初始化表时会填充CardStockID,但是当我点击jquery数据表上的Export按钮并再次点击GetAddressErrors方法时,不再填充CardStockID在参数中。

0 个答案:

没有答案