2

I am using jquery data table plugin to populate data in web table using ajax.But i want to populate data by calling a method which is present in js file without making ajax call.Is there any way?

Sharing my code.

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

I make an Ajax call by passing url and get the data in json format, but i want to call a method which has data and pass it to to data table, without making ajax call.

4
  • could you share your code ? Commented Feb 10, 2016 at 5:15
  • have you read the documentation for this jquery data table plugin Commented Feb 10, 2016 at 5:16
  • I have shared the code @LearningMode. Commented Feb 10, 2016 at 5:38
  • Thanks for sharing the document @JaromandaX Commented Feb 10, 2016 at 5:38

1 Answer 1

7

You can set custom data by setting data option. Examples and usage details are here http://datatables.net/reference/option/data. Set data option as a function which returns preferred array of data.

Sign up to request clarification or add additional context in comments.

3 Comments

Not able to upvote as i dont have enough credits.Thanks @Pranav C Balan.
Could you also tell how can i update selected rows based on id of that row?
You can set columnDefs option and render output based on data using nested property render , datatables.net/examples/advanced_init/column_render.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.