X-Editable and Bootstrap datatables

前端 未结 1 678
南旧
南旧 2021-01-22 01:57

I\'ve tried with no success to implement x-editable in bootstrap datatables, the reason being when i update an element from x editable, the datatable fails to recognize those ch

相关标签:
1条回答
  • 2021-01-22 02:54

    The problem is that for performance reasons, Datatables caches the table into memory so actually the DOM table is different from the in-memory table. And when you modify the DOM, it doesn't change the table in-memory.

    Therefore, Datatables created a function helper : invalidate() that you can apply on a row http://datatables.net/reference/api/row%28%29.invalidate%28%29 (there is a multiple rows version too).

    Or you can still use the function data() which is less CPU consuming (recommended).

    I would do something like this :

    $('.xeditable').on('save', function(e, params) {
        var $tr = $(e.target).closest('tr');
        var newValue = params.newValue;
        //If you didn't save the datatable into a var table, you need to call this line :
        //var table = $('#example').DataTable();
        table.row(tr).data(newValue);
        //Or table.row(tr).invalidate(); which should read from the DOM directly
    });
    
    0 讨论(0)
提交回复
热议问题