ParamQuery grid support forum

General Category => Help for ParamQuery Grid (free version) => Topic started by: BeeBuu on January 07, 2014, 09:45:25 pm

Title: What's the JSON format needed?
Post by: BeeBuu on January 07, 2014, 09:45:25 pm
Hello,all.
As you know i'm a newbie.I'm learning pqgrid follow the tutorial,now I put following codes in my web page,but got a blank data view, please help me if you can,tons of thanks.

    $(function () {
    var obj = { width: 700, height: 400, title: "Grid From JSON data", flexHeight: true };
    obj.colModel = [{ title: "Rank", width: 100, dataType: "integer", dataIndx: "rank" },
                       { title: "Company", width: 200, dataType: "string", dataIndx: "company" },
                       { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right", dataIndx: "revenues" },];

        obj.dataModel = {
                location: "remote",
                sorting: "local",
                dataType: "JSON",
                method: "GET",
        getUrl: function () {
                return {url: "/tt.php"};
            },
        getData: function (dataJSON) {
            var data = dataJSON.data;
            return { data: dataJSON.data };
        }
                };
        $("#grid_json").pqGrid(obj)
});

And the tt.php code are:
<?php
$json_arr = array('data'=>array(array('A','3','B'),array('C','3','D')));
$php_json = json_encode($json_arr);
echo $php_json;
?>

Title: Re: What's the JSON format needed?
Post by: paramvir on January 07, 2014, 10:10:31 pm
Since your data in tt.php is in array format, you need not mention dataIndx in colModel

So your colModel should be

 obj.colModel = [{ title: "Rank", width: 100, dataType: "integer"},
                       { title: "Company", width: 200, dataType: "string"},
                       { title: "Revenues ($ millions)", width: 150, dataType: "float", align: "right" }];
Title: Re: What's the JSON format needed?
Post by: angelahlp on June 04, 2014, 10:12:59 am
But what if you NEED the dataIndx defined?
Title: Re: What's the JSON format needed?
Post by: paramvir on June 04, 2014, 11:07:22 am
There is no problem in defining the dataIndx.

Please refer to the API
http://paramquery.com/api#option-column-dataIndx