jquery - jsGrid loadData 不起作用

标签 jquery ajax jsgrid

我使用 Ajax 将数据加载到 jsGrid 中。

我有以下代码:

$("#jsGrid").jsGrid({
    width: "100%",
    height: "100%",

    autoload:   true,
    paging:     true,
    pageSize:   15,
    pageButtonCount: 5,
    pageIndex:  1,

    controller: {
        loadData: function(filter) {
            var d = $.Deferred();
            $.ajax({    url: "/api/index.php/get_data",
                        contentType: "application/json; charset=utf-8",
                        data: {a:(filter.page?filter.page:0)},
                        dataType: "json"
                    }).done(function(response){
                        console.info(response);
                        d.resolve(response);
                    });
            return d.promise();
        }
    },
    fields: [
        { name: "ID", type: "number", width:50 },
        { name: "platform", type: "text", width: 100 },
        { name: "title", type: "text", width: 150 },
        { name: "url_image", type: "text", width: 200 },
        { name: "url", type: "text", width: 200 },
        { name: "cost", type: "text", width: 50 }
    ]
});

});

ajax 调用返回一个对象数组,但它不会填充到表中。

出了什么问题?

最佳答案

The ajax call returns an array of objects but it does not populate in the table.

What's wrong?

首先:ajax 本身就是一个 promise ,所以你可以返回它自己。

第二:高度:“100%”,:这会将高度设置为一个小值(在我的计算机上为“.jsgrid-grid-body”的值) “只有 3px!!!)。您可以使用默认值或设置其他值。

代码片段:

$("#jsGrid").jsGrid({
  width: "100%",
  height: "auto",

  autoload:   true,
  paging:     true,
  pageSize:   5,
  pageButtonCount: 5,
  pageIndex:  1,

  controller: {
    loadData: function(filter) {
      return $.ajax({
        url: "https://api.github.com/repositories",
        dataType: "json"
      });
    }
  },
  fields: [
    {name: "name", width: 50},
    {name: "full_name", width: 100}
  ]
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid-theme.min.css"/>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jsgrid/1.5.3/jsgrid.min.js"></script>


<div id="jsGrid"></div>

关于jquery - jsGrid loadData 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41335918/

相关文章:

javascript - 限制jsgrid在空时添加新行

JavaScript/JQuery : use $(this) in a variable-name

jquery - 根据类别淡化车身颜色

javascript - 如何使用 Javascript 更改下拉组合框值

javascript - jquery 如何在单击按钮时停止 $.ajax

javascript - 如何使用 jsGrid 将项目获取到字段中的下拉列表?

jquery - 禁用下拉菜单并仍然提交值?

javascript - 两种类型的输入由选项卡分隔,我只能传递选项卡被选中的输入

javascript - 如何防止ajax在更改输入数据时发送多个请求

jquery - jsgrid 多个自定义控制按钮?