【问题标题】:arrary in Datatable make customise in array and display coluns according new coloumsDatatable中的arrary在数组中自定义并根据新列显示列
【发布时间】:2019-11-06 16:22:49
【问题描述】:

在使用数据表显示时,动态数据以数组为输入,数组中的自定义字段。

【问题讨论】:

  • 你能问一个具体的问题吗?

标签: jquery html css ajax


【解决方案1】:

为分配为数据表的<table> 元素指定任何特定类

JS

var BindDatatable = function (data) {
        table = $('.datatable').DataTable({
            retrieve: true,
            data: data,
            columns: [
                { data: 'EmployeeID' },
                { data: 'EmployeeName' },
                { data: 'DOB', type: 'date-dd-mmm-yyyy', targets: 0, width: '100px' },
                { data: 'Salary' },
                { data: 'DepartmentName' },
                { data: 'CountryName' },
                { data: 'StateName' },
                { data: 'CityName' },
                {
                    data: null,
                    render: function (data, type, row) {
                        var html = "";
                        html += '<button class="btn btn-primary" data-viewtype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="View"><span class="fa fa-user"></span></button>&nbsp';
                        html += '<button class="btn btn-success" data-edittype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="Edit"><span class="fa fa-pencil"></span></button>&nbsp';
                        html += '<button class="btn btn-danger" data-deletetype="' + data.EmployeeID + '" id="' + data.EmployeeID + '" title="Delete"><span class="fa fa-trash"></span></button>';
                        return html;
                    }
                }
            ],
        });
    };

HTML

    <table id="table_id" class="datatable">
        <thead>
            <tr>
                <th>EmployeeID</th>
                <th>EmployeeName</th>
                <th>DOB</th>
                <th>Salary</th>
                <th>Department</th>
                <th>Country</th>
                <th>State</th>
                <th>City</th>
                <th>Action</th>
            </tr>
        </thead>
    </table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-20
    • 1970-01-01
    • 2014-08-12
    • 2022-01-18
    • 1970-01-01
    • 2018-04-26
    • 2020-11-14
    • 2018-07-02
    相关资源
    最近更新 更多