0

请帮帮我 !!这个错误是怎么回事?我更改了表的类名,但我无法更改它并出现此错误? 在此处输入图像描述在此处输入图像描述

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"));
4

2 回答 2

1

id正如 Tammy 提到的,您需要为您的列定义一个自定义项:

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

于 2021-01-08T00:01:17.347 回答
0

我遇到过同样的问题:

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

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

于 2021-04-18T19:09:35.020 回答