简体   繁体   中英

Adding data to jQuery-Flexigrid without ajax-request

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?

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"});

Did you use the eval() ?

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

or try

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

hope this helps

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM