Reloading data table with new parameter values

Reloading data table with new parameter values

8karthik88karthik8 Posts: 8Questions: 3Answers: 0

I have a data table that is initialized and loaded on a selection of a dropdown1. Lets say now the Parameter NetworkID is “Mark”

var table1 = $('#table1').DataTable({ dom: "Bfrtip",language: { search: "" },            
            ajax: "/api/ControllerName/MethodName/"  + NetworkID + "/" + AE ,            
            columns: [                
                {
                    "data": "Product",
                    "width": "Auto",
                    "render": function (data) {
                        var productName = '';
                        for (var i = 0; i < data.length; i++) {
                            productName = productName + ' ' + data[i].name;
                        }
                        return productName;
                    }
                },
                //Few More columns here
            ],            
            select: true
});

Question??:
I need to reload the data table using new parameters , that should fetch new data(i.e. new product’s) on change event of dropdown2 . Lets say the parameter NetworkID now is “John”
Below is what I tried on dropdown2 event change and it did not work.

$('#table1).DataTable().ajax.reload();

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @8karthik8 ,

    That should work. You would want to add the select value in ajax.data. In what way didn't it work?

    Cheers,

    Colin

  • 8karthik88karthik8 Posts: 8Questions: 3Answers: 0

    It was still using 'Mark' as parameter value .

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah, yep, I see. The problem is because it's declared in the original URL - as a fixed string, so that's the value it will always be. The best bet is to change the URL with ajax.url().

  • 8karthik88karthik8 Posts: 8Questions: 3Answers: 0

    Thank you Colin, worked like magic. Thank you much

This discussion has been closed.