How can DataTable generate rows by ajax call in ASP.NET controller

How can DataTable generate rows by ajax call in ASP.NET controller

woodmanhuwoodmanhu Posts: 3Questions: 2Answers: 0
edited December 2015 in Free community support

I have an origional ajax written in my .js file:

$.ajax({

            cache: false,
            type: "GET",
            url: "project/getValue",
            data: {
                "DateFrom": datefrom,
                "DateTo": dateto,
                "Name1": Name1,
                "Name2": Name2,
                "Name3": Name2,
            },
            success: function (data) {.....}

My question is that, can DataTable generate a table using my ajax call or this ajax call should be written in the DataTable statement? like:

$("#DataTable").DataTable({
"ajax" : {

          cache: false,
            type: "GET",
            url: "project/getValue",
            data: {
                "DateFrom": datefrom,
                "DateTo": dateto,
                "Name1": Name1,
                "Name2": Name2,
                "Name3": Name2,
            }

});
// it returns "Cannot read property 'length' of undefined" error in developer console.

I'm kind of confused about those ajax examples datatables.net provided.

$('#example').DataTable( {
"ajax": "data/arrays.txt"
} );

The issue is I don't have a file named arrays.txt and I understand this txt is generated from ajax call back. But in my case I need to use that url I defined in ajax to call controller in ASP.net MVC then the controller returns the Json result of dataset. So can DataTable render the raw data returned from controller and if so, how can I do that?

By the way the result of dataset that controller returns to me is just like the data that datatable.net example provided. It's formatted like:

[ [
"Tiger Nixon",
"System Architect",
"Edinburgh",
"5421",
"2011/04/25",
"$320,800"
],
[
"Garrett Winters",
"Accountant",
"Tokyo",
"8422",
"2011/07/25",
"$170,750"
] ]

I will be appreciated if anyone can give me the answer.

Thank you

Kevin

This discussion has been closed.