首页 > 编程语言 > javascript > dojo DataGrid使用ajax同步数据
2012
10-12

dojo DataGrid使用ajax同步数据

DataGrid配合ItemFileWriteStore可以很方便利用ajax同步表格数据,展示数据库内容。

假设获取json数据的api接口为api.php?m=gettask

约定返回的json格式为

 

{"items":[{"id":"0","taskName":"TC001","total":"80000","completeCount":"39485","okCount":"2","addTime":"2012-10-03","lastTime":"2012-10-19"},{"id":"0","taskName":"TC002","total":"1213213","completeCount":"121","okCount":"21","addTime":"2012-10-23","lastTime":"2012-10-24"}]}

核心代码如下

        var taskLayout = [[
            { name: "任务id", "field": "id", 'width': "120px" },
            { name: "任务名称", "field": "taskName", 'width': "120px" },
            { name: "任务总条数", "field": "total", 'width': "150px;" },
            { name: "完成条数", "field": "completeCount", 'width': "150px" },
            { name: "成果条数", "field": "okCount", 'width': "120px" },
            { name: "添加时间", "field": "addTime", 'width': "80px" },
            { name: "使用时间", "field": "lastTime", 'width': "120px" }
        ]];

        createTaskList = function(){
            var data1 = new dojo.data.ItemFileWriteStore({
                    url: "api.php?m=gettask"
            });
            var grid = new dojox.grid.EnhancedGrid({
                id: 'grid',
                store: data1,
                structure: taskLayout,
                rowSelector: '20px'},
            document.createElement('div'));
            dojo.byId("mydijitDestination").appendChild(grid.domNode);
            grid.startup();
        };

最后编辑:
作者:NINE
这个作者貌似有点懒,什么都没有留下。

留下一个回复

你的email不会被公开。