在Angular中将“编辑器”添加到datatable.net

时间:2019-10-10 17:03:26

标签: angular datatables

我得到“类型'StaticFunctions'不存在属性'Editor'。”初始化datatables.net编辑器时发生错误。 另一方面,“选择”和“按钮”参数还有另一个问题,说“设置”类型中的属性不存在。

export class EmpleadosComponent implements OnInit {


constructor() { }

ngOnInit() {
    let  dataSet = [
        ["Pepe", "Tiger Nixon", "System Architect"],
        ["Juan", "Garrett Winters", "Accountant"],
        ["Javier", "Ashton Cox", "Junior Technical Author"],
    ];



    //tabla responsive con las columnas + dataSet
    $(document).ready(function () {
        $('#example').DataTable({
            data: dataSet,
            columns: [
                { title: "Nombre"},
                { title: "Apellidos" },
                { title: "Departamento" },
             ],
            responsive: true
        });
    });

//editor
var editor;

$(document).ready(function () {
    editor = new ($.fn.dataTable as any).Editor({  // <-- Editor gives error
        ajax: "../php/staff.php",
        table: "#example",
        fields: [{
            label: "First name:",
            name: "first_name"
        }, {
            label: "Last name:",
            name: "last_name"
        }, {
            label: "Position:",
            name: "position"
        }]
    });

    $('#example').DataTable({
        dom: "Bfrtip",
        ajax: "../php/staff.php",
        columns: [
            {
                data: null, render: function (data, type, row) {
                    return data.first_name + ' ' + data.last_name;
                }
            },
            { data: "position" },
        ],
        select: true,   // <-- from select gives error
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit", editor: editor },
            { extend: "remove", editor: editor }
        ]
    });
});

我导入了所有库,并进行了所有npm安装。 我知道datatable.net对于Angular不值得,但是应该可以通过任何方式解决。

谢谢。

0 个答案:

没有答案