How to use one ajax datasource with multiple JQuery Datatables

How to use one ajax datasource with multiple JQuery Datatables

sdyson3sdyson3 Posts: 4Questions: 3Answers: 0
edited December 2020 in Free community support

There are two datatables on the same page and both have different columns.

Is there a way to use the same ajax datasource to draw multiple tables? I am trying avoid multiple calls to database.

       $('#gvData').DataTable({
        "processing": true,
        //"serverSide": true,
        "bPaginate": false,
        "bFilter": false,
        "bInfo": false,
        "scrollY": "300px",
        "scrollCollapse": true,
        "bDestroy": true,

        "ajax": {
            "dataType": 'json',
            "contentType": "application/json",
            "type": "POST",
            "url": "myform.aspx/GetData",
            "data": function (d) {
                return "{ regDate: '" + regDate + "', cmdName: '" + command + "'}";

            },
            "dataSrc": function (json) {
                adata = json;
                return $.parseJSON(json);
            }
        },

        "columns": [{
            "data": "Source_Name"
        },
          {
              "data": "Record_Count",
              "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                  $(nTd).html("<a href='" + oData.Record_Count + "' id= '" + iRow + "' style='color: black; text-decoration: none;' onclick='return GetSelectedRow(this, 'completed');' >" + oData.Record_Count + "</a>");
              }
          }
        ]
    });

Answers

This discussion has been closed.