jqGrid 返回空白单元格 [英] jqGrid returns blank cells

查看:17
本文介绍了jqGrid 返回空白单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎无法使以下 jqGrid 代码工作http://cablegate.politicswiki.ie/stackoverflow.html

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.

对应的JavaScript代码如下

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

这篇关于jqGrid 返回空白单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆