Pass parameters to server

Pass parameters to server

kirankskiranks Posts: 3Questions: 1Answers: 1

Hi,
i am using below code to pass value of dropdown,so that table gets refreshed according to the value

Datatable initialisation:

$('#administrationData')
.dataTable({
"responsive": true,
"info": false,
"searching": false,
"iDisplayLength": 10,
"bFilter": false,
"bLengthChange": false,
"aoColumns": [
{ mData: 'Status' },
{ mData: 'UpdatedDate' },
{ mData: 'UpdatedBy' },
{
responsivePriority: 2,
bSearchable: false,
bSortable: false,
mRender: function (data, type, full) {
return AdminActionColumn(full);
}
}
]
,
"ajax": {
type: "Get",
"url": url,
"data": function (d) {
return $("#Dropdwnlist").val();
},
"dataSrc": ""
}
});

Reload Code:

$('#administrationData').DataTable().ajax.reload(null, false).draw();

i am not receiving table default parameters when i do this

Kindly help

Thanks

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin

    What default parameters? You aren't using server-side processing, so DataTables doesn't need to send any parameters.

    Allan

  • kirankskiranks Posts: 3Questions: 1Answers: 1

    hi Allan,

    Below code would give you more clear picture

    Datatable initialisation:

    $('#administrationData')
    .on('preXhr.dt', function (e, settings, data) {
    debugger
    data.id = $("#dropdown").val();
    data.sEcho = data.draw;
    data.iDisplayLength = data.length;
    data._iDisplayStart = data.start;
    data.iColumns = data.columns.length;
    data.sSortDir_0 = data.order[0].dir;
    data.iSortCol_0 = data.order[0].column;
    data.iSortingCols = data.order.length;
    data.sColumns = ",,,,,,,,,,,,";
    return data; //data;
    })
    .dataTable({
    "ajax": {
    "type": "POST",
    "url": url,
    "dataSrc": ""
    },
    "responsive": true,
    "info": false,
    "processing": true,
    "searching": false,
    "bServerSide": true,
    "iDisplayLength": 10,
    "bFilter": false,
    "bLengthChange": false,
    "aoColumns": [
    { mData: 'Status' },
    { mData: 'UpdatedDate' },
    { mData: 'UpdatedBy' },
    {
    responsivePriority: 2,
    bSearchable: false,
    bSortable: false,
    mRender: function (data, type, full) {
    return AdminActionColumn(full);
    }
    }
    ]

    });
    

    Reload Code:

    $('#administrationData').DataTable().ajax.reload(null, false).draw();

    i am doing server side processing
    default parameters here i meant is sEcho,_iDisplayStart,_iDisplayLength, etc. once i put ajax parameter in datatable initialization, i wont get the default parameters on server

    Thanks

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin

    Yes, your new code in the second post does use server-side processing.

    Can you give me a link to the page showing the issue please. I don't see why you wouldn't be getting the server-side processing parameters with the above.

    Allan

  • kirankskiranks Posts: 3Questions: 1Answers: 1
    edited March 2017 Answer ✓

    Hi allan,

    Thank you for your time.

    Below code worked for me
    Datatable Initialisation

    $('#administrationData')
        .on('preXhr.dt', function (e, settings, data) {
            data.id = $("#dropdown").val();
            return data;
        })
        .dataTable({
            "responsive": true,
            "info": false,
            "processing": true,
            "searching": false,
            "sAjaxSource": url,
            "type":"GET",
            "bServerSide": true,
            "iDisplayLength": 10,
            "bFilter": false,
            "bLengthChange": false,
            "aoColumns": [
                               { mData: 'BankAccountNbr' },
                               { mData: 'Status' },
                               { mData: 'UpdatedDate' },
                               { mData: 'UpdatedBy' },
                               {
                                   responsivePriority: 2,
                                   bSearchable: false,
                                   bSortable: false,
                                   mRender: function (data, type, full) {
                                       return AdminActionColumn(full);
                                   }
                               }
            ]
    
        });
    

    Reload Code:
    adminTable.api().ajax.reload();

    Add "ajax" parameter in datatable initialization changes default parameters, i took the same of and it worked

    Thanks again

    Happy Coding..

  • allanallan Posts: 63,350Questions: 1Answers: 10,443 Site admin
    Answer ✓

    Yes - the preXhr option can be used to send data to the server. The other option is to use ajax.data.

    Allan

This discussion has been closed.