2

我正在使用jTable插件创建表格。它主要专注于 ASP 或 PHP MVC,但我正在尝试使用 javascript/html 和 mongo 后端来实现它。

我浏览了整个jTable API 文档,发现有可能将 json 模式 api 填充到表中,这在 flexigrid 中非常相似。

代码如下所示:

 $(document).ready(function () {
          $('#feeds-table').jtable({
              title: 'Accounts',
              pageSize: 15,
              ajaxSettings: {
                  type: 'GET',
                  dataType: 'json'
              },
              actions: {

              },
              fields: {
                  id: {
                      key: true,
                      list: false
                  },
                  username: {
                      title: 'Username',
                      width: '10%'
                  },
                  email: {
                      title: 'Email',
                      width: '10%'
                  },
                  applications: {
                      title: 'Applications',
                      width: '10%'
                  },
                  sites: {
                      title: 'Sites',
                      width: '10%'
                  },
                  verticals: {
                      title: 'Verticals',
                      width: '10%'
                  },
                  roles: {
                      title: 'Roles',
                      width: '10%'
                  },
                  profiles: {
                      title: 'Record date',
                      width: '30%',
                      type: 'date',
                      create: false,
                      edit: false
                  }
              }
          });
      });

如果有人可以帮助我找出我应该在哪里使用 URL 属性,或者 API 参考中是否有任何其他方法来获取数据并显示在表格中。请告诉我!

4

2 回答 2

1

You can directly load JSON data by setting the 'listAction' to a JSON document .

Example:

actions: {
  listAction: 'url/file.json',
},

Your JSON file needs to have the same fields specified and the next structure:

{
 "Result":"OK",
   "Records":[
    {"PersonId":1,"Name":"Benjamin Button","Age":17,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":2,"Name":"Douglas Adams","Age":42,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":3,"Name":"Isaac Asimov","Age":26,"RecordDate":"\/Date(1320259705710)\/"},
    {"PersonId":4,"Name":"Thomas More","Age":65,"RecordDate":"\/Date(1320259705710)\/"}
   ]
}

The common way is to point the 'listAction' to a server side script (PHP,ASP.NET...) that return the above JSON object.

Check the listAction API reference for more information: ApiReference-listAction

于 2013-06-12T09:16:24.000 回答
0

使用addRecord动作。它使您可以选择clientOnly: true在编辑行时指定哪些将阻止 jtable 进行服务器调用。更多信息 - jtable.org-addRecord

于 2013-10-24T14:17:09.723 回答