Adding data to jQuery-Flexigrid without ajax-request

末鹿安然 提交于 2019-12-23 04:41:46

问题


I want to save some unneeded requests and time for displaying a table the first time and so I thought maybe I could set the initial data directly without any ajax-request. I tried it like that:

$('#testTable').flexAddData('[formatted json here]');

and also that

$('#testTable').addData('[formatted json here]');

But it hasn't any effect. Can I do that and what is the right syntax?


回答1:


Did you use the eval()?

$("#testTable").flexAddData(eval('[formatted json here]'));

or try

$("#testTable").flexAddData(eval('[formatted json here]')).flexReload();

hope this helps




回答2:


I've also met this problem and spent a lot of time trying to solve it. Solution in my case was pretty simple. You just need to specify dataType : "json" obviously in flexigrid() function. Default dataType is XML. So, it don't want to understand JSON:

$("#myTable").flexigrid({dataType : "json"});



回答3:


To supplement Anwar and user1635430 answers, here is an example JSON code:

{
"page": "1",
"total": "9",
"rows": [
    {
        "id": "1",
        "cell": [
            "1",
            "text1",
            "user1",
            "date1"
        ]
    }
 ]
}

The code is done by Anwar, I "stole" it from his answer on some other question.



来源:https://stackoverflow.com/questions/8912543/adding-data-to-jquery-flexigrid-without-ajax-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!