如何在不进行ajax调用的情况下在jquery数据表中填充数据?

时间:2016-02-10 05:11:17

标签: javascript jquery datatable datatables

我正在使用jquery数据表插件使用ajax填充web表中的数据。但是我想通过调用js文件中存在的方法来填充数据而不进行ajax调用。有什么办法吗?

分享我的代码。

 ajax : $.fn.dataTable.pipelineAdv({
            url : oMapUrls.loadDefaultMap,
            pages : !bLivePaginate ? -1 : Global.pageSize,
            method : "POST",
            contentType : "application/json",
            data : function() {
                var requestData = {
                    serverSide : false
                };
                if (bTimeFiltered) {
                    requestData.withInTime = iFilterByTime;
                }
                if (sFilteredVehicleIds) {
                    requestData.vehicleIds = sFilteredVehicleIds;
                }
                return requestData;
            },
            redraw : function() {
                return (getPageName() === "map");
            },
            callback : function(oJSON, request) {
                aLiveFleetData = oJSON.serverResponse.result;
                if (mapRefreshTimer) {
                    window.clearTimeout(mapRefreshTimer);
                }
                setMapRefreshTimer();
            }
        }),
        oCustomization : {
            sExportFunctionCall : oMapUrls.exportLiveFleetReport,
            bAdvanceExport : true,
            bShowDefaultAll : !bLivePaginate
        },
        pageLength : !bLivePaginate ? -1 : Global.rowLength,
        scrollCollapse : false,
        scrollY : iDataTableHeight,
        serverSide : bLivePaginate,
        order : [ [ 3, "desc" ] ],
        columns : [
                {
                    "data" : "trackeeName",
                    "width" : aColumnWidths[0],
                    "class" : "no-word-break",
                    "settings" : {
                        source : function(request, oCallback) {
                            oCallback($.ui.autocomplete.filter(Global.aJSTreeVehicleItems || [], request.term));
                        }
                    },
                    "title" : jQuery.i18n.prop("report.columnTitle.vehicle"),
                    "render" : function(value, type, rowData) {
                        if (type == "display") {
                            rowData.formattedDate = Global.getTimeStampToDate(rowData.dateAndTime, rowData.offset,
                                    rowData.timeZone);

                        }
                        return rowData.trackeeName;

                    }
                },
                {
                    "data" : "firstName",
                    "width" : aColumnWidths[1],
                    "class" : "no-word-break",
                    settings : {
                        source : Global.getDriverSuggestion
                    },
                    "title" : jQuery.i18n.prop("driver.title.txtInfo"),
                    "visible" : Global['show.driver.in.reports'] == 1,
                    "render" : function(value, type, rowData) {
                        return getUserName(rowData.firstName, rowData.lastName);
                    }
                },
                {
                    "data" : "groupName",
                    "width" : aColumnWidths[2],
                    "class" : "no-word-break",
                    "settings" : {
                        source : function(request, oCallback) {
                            oCallback($.ui.autocomplete.filter(Global.aJSTreeGroupItems || [], request.term));
                        }
                    },

我通过传递url并以json格式获取数据来进行Ajax调用,但我想调用一个包含数据并将其传递给数据表的方法,而不进行ajax调用。

1 个答案:

答案 0 :(得分:3)

您可以通过设置data选项来设置自定义数据。示例和使用详情在http://datatables.net/reference/option/data。将数据选项设置为返回首选数据数组的函数。