How to get name of datatable column?

后端 未结 5 1433
春和景丽
春和景丽 2021-02-18 16:25

I\'m using DataTable 1.10.9 (from https://datatables.net). Columns for the datatable are defined at the initialization step in javascript and each column has a unique name, e.g.

5条回答
  •  忘了有多久
    2021-02-18 16:48

    The following should work for you as per the API document:

    var tableColumns = [{
        name: 'first-name'
    }, {
        name: 'last-name'
    }, {
        name: 'position'
    }, {
        name: 'location'
    }, {
        name: 'salary'
    }]
    
    var table = $('#example').DataTable({
        tableColumns
    });
    
    table.columns().every(function (index) {
    
        console.log(tableColumns[index].name);
    
    });
    

提交回复
热议问题