0

I'm trying to populate a jQuery DataTable using the code below:

Javascript

$(document).ready(function () {
        var data = $('#giveUps').DataTable({
            "bJQueryUI": true,
            "bServerSide": true,
            "bProcessing": true,
            "sAjaxSource": "/GiveUp/GiveUpView",
            "aoColumns": [
                { "type": "text" },
                { "type": "number-range" },
                { "type": "number-range" },
                { "type": "number-range" },
                { "type": "text" },
                { "type": "text" },
                { "type": "number-range" },
                { "type": "text" },
                { "type": "number-range" },
                { "type": "text" },
                { "type": "text" },
                { "type": "number-range" },
                { "type": "number-range" },
                { "type": "text" },
                { "type": "date-range" },
                { "type": "text" },
                { "type": "text" },
                { "type": "number-range" },
                { "type": "text" },
                { "type": "text" }
            ]
        });
    });

My controller:

    public ActionResult GiveUpView()
    {
        var result = GiveUpRepository.Instance.GetGiveUp();
        return Json(result.Take(10).ToList(), JsonRequestBehavior.AllowGet);
    }

I checked in the chrome debug that the response is coming int the Json as bellow:

 [{"AId":"T-2-1471982820928-7","TInfo":382010,"Seg":1,"Mar":10,"Cod":"X","Nick":"BILL","Account":203627,"SecondNick":"XXX","Origin":203627,"Name":"Test","Up":"Yes","Quantity":300,"Price":12.87,"Number":"54360","GiveUpDateTime":"\/Date(1471982820000)\/","Status":"APPROVED","Desk":"","OffHours":1541,"ErrorDescription":"","Key":"T-2-1471982820928-7|382010"}]

But the datatable keeps showing Processing.... Also, there is an HTML table with the id="giveUps" in the cshtml.

What am I missing?

EDIT:

I change the function for the following:
 $(document).ready(function () {
            var data = $('#giveUps').DataTable({
                "bJQueryUI": true,
                "bServerSide": true,
                "bProcessing": true,
                "sAjaxSource": "/GiveUp/GiveUpView",
                "aoColumnDefs": [
                { "mDataProp": "AId", "aTargets": [1] },
                { "mDataProp": "TInfo", "aTargets": [2] },
                { "mDataProp": "Seg", "aTargets": [3] },
                { "mDataProp": "Mart", "aTargets": [4] },
                { "mDataProp": "Cod", "aTargets": [5] },
                ...
                ]
            });
        });`

It's working fine but the time is not showing as dateTime but as string /Date(1471982820000)/ any sugestions?

Lucas Gazire
  • 301
  • 5
  • 16
  • Are you sure that no errors have occurred? When the 'Processing...' message is displayed and never goes away, that is usually an indication that there is an error. This could be a datatype issue. – David Tansey Aug 25 '16 at 18:09
  • Did you mean a jquery Datatable? – Blue Eyed Behemoth Aug 25 '16 at 18:09
  • 1
    you may want to research what the json structure should be... you might need to add `return Json(new {aaData = result.Take(10).ToList()}, JsonRequestBehavior.AllowGet)`; or something – JamieD77 Aug 25 '16 at 18:11
  • David Tansey, i double checked there's no error and also i'm receiving the json, i can see it on the response in the network debug from chrome. – Lucas Gazire Aug 25 '16 at 18:28
  • After done what JamieD77 said i'm getting the following error: table id=giveUps - Requested unknow parameter '0' for row 0, column 0 – Lucas Gazire Aug 25 '16 at 18:32
  • I change the Controller to convert the item toJSon: `List json = new List(); foreach (var item in result) { json.Add(JsonConvert.SerializeObject(item)); }` But now i'm getting the first char of the json object and putting each one in a row. – Lucas Gazire Aug 25 '16 at 19:04
  • Are you omitting something in your example of initialization? Could you double check that columns in your html markup matches the columns in the datatables config ? – Javier Aug 25 '16 at 19:09
  • Nope, i'm not omitting anything, double checked and the numbers are equal, there are empty values i don't know if this is a problem. – Lucas Gazire Aug 25 '16 at 19:16

0 Answers0