English 中文(简体)
jqGrid returns blank cells
原标题:

Can t seem to get the following jqGrid code to work http://cablegate.politicswiki.ie/stackoverflow.html

<script type="text/javascript"> 
$(document).ready(function(){
    jQuery("#list2").jqGrid({
        url: http://tables.googlelabs.com/api/query?sql=SELECT * FROM 333136 LIMIT 10&jsonCallback=? ,
        datatype: "json",
        colModel:[
            {name: ident ,index: ident ,label: ident , width:55},
            {name: date ,index: date ,label: date , width:90},
            {name: sourceId ,index: sourceId ,label: sourceId , width:100},
            {name: source ,index: source ,label: source , width:80},
            {name: tags ,index: tags ,label: tags , width:200}      
        ],
        jsonReader: {
            repeatitems: false,
            root: function (obj) { 
                var rows = new Array();
                for(var i = 0; i < obj.table.rows.length;i++)
                {
                    var row = new Object();
                    row.id = obj.table.rows[i][0];
                    row.cell = obj.table.rows[i];
                    rows[i] = row;
                }
                return rows;
            },
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.table.rows.length; }
        },
        rowNum:10,
        rowList:[10,20,30],
        pager:  #pager2 ,
        sortname:  id ,
        viewrecords: true,
        sortorder: "desc",
        caption:"JSON Example"
    });
    jQuery("#list2").jqGrid( navGrid , #pager2 ,{edit:false,add:false,del:false});
});
</script> 

Have tried a number of things to get it to work. Nothing seems to do it.

问题回答

I find the question very interesting. So I modified a little your code and it work now. You can see the results live here.

The corresponding JavaScript code is following

jQuery(document).ready(function() {
    jQuery("#list2").jqGrid({
        url:  http://tables.googlelabs.com/api/query?sql=  +
                encodeURI( SELECT * FROM 333136 LIMIT 10 ) +  &jsonCallback=? ,
        postData: "",     // don t send any typical jqGrid parameters
        datatype: "json", // or "jsonp"
        colModel:[
            {name: ident ,index: ident ,key:true,width:60,sorttype: int },
            {name: date ,index: date , width:130},
            {name: sourceId ,index: sourceId ,width:80,sorttype: int },
            {name: source ,index: source ,width:150},
            {name: tags ,label: tags ,width:350}      
        ],
        jsonReader: {
            cell: "", // the same as  cell: function (obj) { return obj; }
            root: "table.rows",
            page: function (obj) { return 1; },
            total: function (obj) { return 1; },
            records: function (obj) { return obj.table.rows.length; }
        },
        rowNum:10,
        rowList:[10,20,30],
        pager:  #pager2 ,
        sortname:  id ,
        sortorder: "desc",
        viewrecords: true,
        loadonce: true,
        height: "100%",
        caption: "How to query Google Fusion Tables"
    });
    jQuery("#list2").jqGrid( navGrid , #pager2 ,{edit:false,add:false,del:false});
});




相关问题
JQuery/MVC Search Issue

I have inherited a piece of work where the entry screen shows a summary of 20 calculated variables. E.g. Var A (250), Var B (79). Clicking on any of these links takes the user to a view with a ...

jQuery quicksearch plug-in tinkering with JSON

I ve implemented the quicksearch plugin by Rik Lomas and I love it for an application in a custom CMS I m building. I was wondering though, since I m going to have a bizillion items in the table if ...

JSON with classes?

Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...

PHP json_decode question

i m trying to use json_decode to combine a few json objects and then re-encode it. my json looks like: { "core": { "segment": [ { "id": 7, "...

Converting JSON data to Java object

I want to be able to access properties from a JSON string within my Java action method. The string is available by simply saying myJsonString = object.getJson(). Below is an example of what the string ...

热门标签