【问题标题】:What happened to this error? I changed the class name of the table, but I cannot change it and this error occurs?这个错误是怎么回事?我更改了表的类名,但我无法更改它并出现此错误?
【发布时间】:2023-03-30 19:35:01
【问题描述】:

请帮帮我!!这个错误是怎么回事?我更改了表的类名,但我无法更改它并出现此错误?

new gridjs.Grid({
    columns: [{ name: 'ID', width: '60px' },
        { name: 'Name', width: '200px' },
        { name: 'Position', width: '300px' },
        { name: 'Email', width: '200px' },
        { name: 'Tel', width: '100px' },
        { name: '', width: '40px', sort: false }],
    sort: true,
    search: true,
    pagination: {
        limit: 5,
    },

    className: {
        table: 'table',
        thead: 'thead-dark'
    },

    language: {
        'search': {
            'placeholder': ' Search...'
        },
    },
    server: {
        url: 'http://localhost:55289/ManageUser/GetUserList',
        then: data => data.map(user => [user.id,
            user.first_name + '\xa0\xa0\xa0' + user.last_name,
            user.position, user.email,
            user.tel_mobile,
            gridjs.html(`<a id="button-delete" href="/ManageUser/Delete/${user.id}"><button class="btn btn-danger"><i class="fa fa-close"></i></button></a>`)])
    }
}).render(document.getElementById("user-table"));

【问题讨论】:

  • 你需要展示你的代码,而不是库中错误信息的实现。
  • 正如@Barmar 所说,请显示您的代码,避免共享代码图像显示您的代码而不是图像,以便有人可以复制和实现上面的东西。
  • 我已经更新了。
  • 您是否尝试过将id 属性添加到您的columns 子级,而name 为空?我实际上不认为您应该使用空的name,因为gridjs.io/docs/config/columns 需要它
  • 在错误消息中它说缺少列的 id。您在哪里为每列定义 id?

标签: javascript jquery gridjs


【解决方案1】:

正如 Tammy 所说,您需要为您的列定义一个自定义 id

const grid = new Grid({
  columns: [{
     id: 'name',
     name: 'Name'
  }, {
     id: 'email',
     name: 'Email'
  }, {
     id: 'phoneNumber',
     name: 'Phone Number'
  }],
  data: [
    { name: 'John', email: 'john@example.com', phoneNumber: '(353) 01 222 3333' },
    { name: 'Mark', email: 'mark@gmail.com', phoneNumber: '(01) 22 888 4444' },
  ]
});

演示:https://gridjs.io/docs/examples/import-json

【讨论】:

    【解决方案2】:

    我遇到了同样的问题:

    Could not find a valid ID for one of the columns. 
    Make sure a valid "id" is set for all columns
    

    修复就是 Tammy 提到的,我有一个空的命名列。

    【讨论】:

      猜你喜欢
      • 2022-11-18
      • 1970-01-01
      • 2018-05-13
      • 2015-11-12
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      相关资源
      最近更新 更多