Author Topic: What's the JSON format needed?  (Read 3888 times)

BeeBuu

  • Newbie
  • *
  • Posts: 2
    • View Profile
What's the JSON format needed?
« 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;
?>


paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: What's the JSON format needed?
« Reply #1 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" }];

angelahlp

  • Pro Enterprise
  • Jr. Member
  • *
  • Posts: 51
    • View Profile
Re: What's the JSON format needed?
« Reply #2 on: June 04, 2014, 10:12:59 am »
But what if you NEED the dataIndx defined?

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6263
    • View Profile
Re: What's the JSON format needed?
« Reply #3 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