根据表ID获取DataTable设置

时间:2017-06-27 13:17:37

标签: javascript jquery datatable

我使用过JQuery数据表,并且我已经创建了常用方法来自定义所有网格。

function GridCommon(id) {
    this.ControlId = id;


    var columns = [];
    var service = "";
    var zeroRecords = "";
    var processingStr = "";
    var jsonVal = ko.toJSON(this.ControlId).replace(/'/g, "\\'");
    var obj = "{'DataTablename':'" + jsonVal + "'}";
    var recLength = 10;
    var sortColumn = 0;
    var sortOrder = "ASC";
    $.ajax({
        type: "POST",
        url: 'Service/DataGridService.asmx/GetTableSttings',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: obj,
        async: false,
        success: function (arg) { //call successfull   
            Result = arg.d;
            var val = JSON.parse(Result);
            columns = MapColumnDefsDbTableToGrid(JSON.parse(val.ColumnDefinition));
            columnList = val.ColumnDefinition;
            service = val.AjaxSource;
            zeroRecords = val.NoRecordsText;
            processingStr = val.ProcessingText;
            recLength = val.DisplayLength;
            prametersList = JSON.parse(val.ParameterList);
            sortColumn = val.initialSortColumnNumber;
            sortOrder = val.initialSortColumnOrder;
        },
        error: function (xhr) {
            alert('Error');
        }
    });

    this.ColumnDefs = columns;
    this.ServiceMethod = service;
    this.NoRecordsText = zeroRecords;
    this.ProcessingText = processingStr;
    this.RecordLength = recLength;
    this.InitialSortColumnNumber = sortColumn;
    this.InitialSortColumnOrder = sortOrder;
}

我正在使用此方法初始化多个网格。我的问题出现在分页中。在进行分页时,它没有获得正确的网格设置 oSettings 。(它最后初始化网格设置。)有什么方法可以使用表格ID获取数据表设置? 或者还有其他方法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

能够找到解决方案。

 var newSettings = $("#currentGrid").dataTable().fnSettings();

Addtional:

如果需要获取当前网格ID,可以按如下方式进行。

var currentGrid = oSettings.sTableId;