AJAX call not passing latest value for serverside processing

AJAX call not passing latest value for serverside processing

brazenvoidbrazenvoid Posts: 2Questions: 1Answers: 0
edited July 2014 in Free community support

var table = $('#emails_table');
I have written a minimal server side processing script for datatables v1.10.0. The server requires the product id for getting records from database, it gets it from select2 plugin based selector selection. The ajax call always passes the value first sent by it, a behavior reminiscent of cached data.

var table = $('#emails_table');
table.dataTable (
    {
        aoColumns: [
        {
            sClass: "center",
            mRender: function (data)
            {
                if (data == '1')
                {
                    return '<input name="row_check" type="checkbox" class="checkboxes" checked="checked" value="1">';
                }
                else if (data == '2')
                {
                    return '<input name="row_check" type="checkbox" class="checkboxes" checked="" value="0">';
                }
            },
            sWidth: '24px',
            bAutoWidth: false,
            bSortable: false },
        {   bSortable: true  },
        {   bSortable: true  },
        {   bSortable: true  },
        {   bSortable: true  }
        ],
        pagelength: 10,
        pagingType: "bootstrap_full_number",
        language:
        {
            lengthMenu: "  _MENU_ records",
            paginate:
            {
                previous:"Prev",
                next:"Next",
                last:"Last",
                first:"First"
            }
        },
        aoColumnDefs : [
        {
            orderable : false,
            aTargets : [0]
        }],
        order : [],
        processing : true,
        serverSide : true,
        deferRender : true,
        iDeferLoading : 0,
        ajax :
        {
            type : "POST",
            url  :  '<?php echo get_records_url(); ?>',
            data : {product : $('#product_search option:selected').val()} // this doesn't get the latest value
        }
    });

$("#show_emails").click(function ()
    {
        table.dataTable().fnClearTable(0);
        table.dataTable().fnDraw();
    }); 

The button is to be pressed before getting records based upon newer value of product. Setting up an alert in the show_emails button shows the change of value on different selection but ajax still sends the first ever value.

I have also tried this with a variable and refreshing its value in the button's click event to no avail. Please help.

Answers

  • brazenvoidbrazenvoid Posts: 2Questions: 1Answers: 0

    Fixed by using ajax.data as function and table.api().reload() in button click event.

This discussion has been closed.