Adding data to jQuery-Flexigrid without ajax-reque

2019-06-13 16:13发布

问题:

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.