Data fetching Url calling twice

Data fetching Url calling twice

kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1

data Fetching url calling twice. script attached.

$(document).ready(function () {
    $('#tCity').DataTable(
    {
        "order": [[2, "asc"]],
        "pagingType": "numbers",
        "columnDefs": [
            { "className": "text-center custom-middle-align", "targets": [0], "width": "7%", "searchable": false, "orderable": false },
            { "className": "text-center custom-middle-align", "targets": [1], "width": "10%", "searchable": true, "orderable": true, "visible": false },
            { "className": "text-left custom-middle-align", "targets": [2], "searchable": true, "orderable": true },
            { "className": "text-center custom-middle-align", "targets": [3], "width": "10%", "searchable": true, "orderable": true, "visible": false },
            { "className": "text-left custom-middle-align", "targets": [4], "searchable": true, "orderable": true },
            { "className": "text-center custom-middle-align", "targets": [5], "width": "8%", "searchable": false, "orderable": false },
        ],
        "language":
            {
                "processing": "<div class='overlay custom-loader-background'><i class='fa fa-cog fa-spin custom-loader-color'></i></div>"
            },
        "processing": true,
        "serverSide": true,
        "ajax":
            {
                "url": "City.aspx/GetCityList",
                "contentType": "application/json",
                "type": "GET",
                "dataType": "JSON",
                "data": function (d) { return d; },
                "dataSrc": function (json) {
                    json.draw = json.d.draw;
                    json.recordsTotal = json.d.recordsTotal;
                    json.recordsFiltered = json.d.recordsFiltered;
                    json.data = json.d.data;
                    return json.data;
                }
            },
        "columns": [
                    { "data": "RowNumber" },
                    { "data": "iCityId" },
                    { "data": "strCity" },
                    { "data": "iStateId" },
                    { "data": "strState" },
                    { "data": "Action" }
        ]
    });
});

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Made a test case for you:
    http://live.datatables.net/ziyeqapi/1/edit

    The only difference is the columns (used the Datatables example) and changed the dataSrc function to remove .d.

    The test case only fetches the data once. Do you have a Datatables API call within the rest of your JS the performs draw()?

    Kevin

  • kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1

    If i remove .d then data not fetched.

  • kalpesh2804kalpesh2804 Posts: 10Questions: 3Answers: 1
    edited December 2017

    I found Its a bug.

    I need to use dataTables.responsive.min.js 2.2.1 build to fix this issue.

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Responsive isn't shown in your options above, but yes, if you were using 2.2.0 then you would indeed need to update to 2.2.1.

    Allan

This discussion has been closed.