My script produces data but jQuery DataTables doesn't load it and shows the following error:

DataTables warning: table id=example - Requested unknown parameter 'FTR_Kno' for row 0

Should I use mvc-datatables?

View:

<link href="~/Content/DataTables/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="~/Content/DataTables/css/dataTables.jqueryui.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.js"></script>
<script src="~/Scripts/DataTables/jquery.dataTables.min.js"></script>
<!DOCTYPE html>

<html>
<body>
    <div>
        <input id="Button1" type="button" value="button" />
    </div>
    <div>
        <form>
            <table id="example">
                <thead>
                    <tr>
                        <td>FTR_Kno</td>
                        <td>FTR_KodBelge</td>
                        <td>FTR_TarihBelge</td>
                        <td>TDR_KodTedarikci</td>
                        <td>KRM_AckAd</td>
                        <td>FTR_Ack</td>
                        <td>FTS_Ack</td>
                    </tr>
                </thead>
                <tbody>
                    @*<tr>
                    <td>a</td>
                    <td>a</td>
                    <td>a</td>
                    <td>a</td>
                    <td>a</td>
                    <td>a</td>
                    </tr>*@
                </tbody>
            </table>
        </form>
    </div>

</body>
</html>

<script type="text/javascript">
    $(document).ready(function () {
        $("#Button1").click(function () {
            alert("bas");
            $.ajax({
                url: '/DataTables/jsonIndex',
                type: "POST",
                dataType: "json",
                success: function (gdata) {
                    alert(gdata);
                    $('#example').DataTable({
                        data: gdata,
                        paging: false,
                        columns: [
                            { "data": "FTR_Kno" },
    { "data": "FTR_KodBelge" },
    { "data": "FTR_TarihBelge" },
    { "data": "TDR_KodTedarikci" },
    { "data": "KRM_AckAd" },
    { "data": "FTR_Ack" },
    { "data": "FTS_Ack" }

                        ]

                    });
                }
            });
        });

    });

</script>

> Controlller :

   [HttpPost]
        public JsonResult jsonIndex()
        {
            CultureInfo c = Thread.CurrentThread.CurrentCulture;
            string userLanguage = c.TwoLetterISOLanguageName;
            Session["language"] = userLanguage;
            string language = Session["language"].ToString();

            ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
            ServiceReference1.Grid grid = new ServiceReference1.Grid();
            grid = client.GetGridInformation("TUR", "lst_afhFTR");
            List<ServiceReference1.Column> column = new List<ServiceReference1.Column>();
            column.AddRange(grid.columnList);
            //Dim columnName As List(Of String) = grid.columnList.Select(Function(f) f.columnName).ToList()
            ViewBag.ColumnList = grid.columnList;
            ViewBag.GridWidth = grid.gridWidth;
            ViewBag.GridHeader = grid.gridHeader;
            client.Close();

            ServiceReference1.Service1Client client1 = new ServiceReference1.Service1Client();
            grid.gridCode = grid.gridCode.Insert(6, " top " + grid.gridMaxRecord.ToString());
            string[] array = grid.gridCode.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            string code = "";
            foreach (string item in array)
            {
                code = code + " " + item;
            }
            grid.gridCode = code;
            List<Dictionary<string, object>> result = new List<Dictionary<string, object>>();
            result.AddRange(client1.GetTable(grid.gridCode));
            ////WebGrid içine gönderilecek data oluşturulması 
            //IList<object> asildata = new List<object>();
            //dynamic data = new List<ExpandoObject>();
            //foreach (var Pairs in result)
            //{
            //    var row = new ExpandoObject();
            //    List<object> row2 = new List<object>();
            //    foreach (var Pair in Pairs)
            //    {
            //        ((IDictionary<string, object>)row).Add(Pair.Key, Pair.Value);
            //        row2.Add(Pair.Value);
            //    }
            //    data.Add(row);
            //    asildata.Add(row2);
            //};
            JavaScriptSerializer js = new JavaScriptSerializer();
            return Json(js.Serialize(result),JsonRequestBehavior.AllowGet);

        }
    }
share|improve this question
    
Wow that's some eye splitting code. – Luke Oct 12 '15 at 8:50
1  
I definitely think your returning json object is wrong. The datatables.js expects a json object with a property named FTR_Kno. Let us see the json object.. – C Sharper Oct 12 '15 at 8:53
    
LİKE .....[{\"FTR_Kno\":\"ALF0000168\",\"FTR_KodBelge\":\"A426797‌​\",\"FTR_TarihBelge\‌​":\"\\/Date(14277492‌​00000)\\/\",\"TDR_Ko‌​dTedarikci\":\"T0002‌​\",\"KRM_AckAd\":\"N‌​Tatlım Gıda Pazarlama Ltd.Şti.\",\"FTR_Ack\":\"\",\"FTS_Ack\":\"Onay Bekliyor\"},{\"FTR_Kno\":\"ALF0000169\",\"FTR_KodBelge\":\"a‌​426800\",\"FTR_Tarih‌​Belge\":\"\\/Date(14‌​28699600000)\\/\",\"‌​TDR_KodTedarikci\":\‌​"T0002\",\"KRM_AckAd‌​\":\"NTatlım Gıda Pazarlama Ltd.Şti.\",\"FTR_Ack\":\"\",\"FTS_Ack\":\"Otomatik Onay\"},{\"FTR_Kno\":\"ALF0000197\",\"FTR_KodBelge\":\"B8774‌​97\",\"FTR_TarihBelg‌​e\":\"\\/Date(143310‌​6000000)\\/\",\" – bgmm Oct 12 '15 at 9:25
    
Is datatables.js case sensitive? Because the error is Ftr_Kno but your poperty is FTR_Kno. Or is that just a copy-to-the-question issue? – freedomn-m Oct 12 '15 at 9:31
    
freedomn-m You are very careful :) thanks but erros is not copy so I write (no copy) error.It is my mistake.Error is not this. – bgmm Oct 12 '15 at 9:38
up vote 1 down vote accepted

You're encoding into JSON twice, first with Serialize() and then with Json().

Replace:

JavaScriptSerializer js = new JavaScriptSerializer();
return Json(js.Serialize(result),JsonRequestBehavior.AllowGet);

with:

return Json(result, JsonRequestBehavior.AllowGet);
share|improve this answer
    
very but very Thank you – bgmm Oct 12 '15 at 12:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.