【问题标题】:Bootstraptable edit row permanently?Bootstraptable 永久编辑行?
【发布时间】:2017-08-06 04:59:28
【问题描述】:

我正在使用 bootstrap-table.js 创建表。我目前的问题是每次编辑行数据都会在对列进行排序后消失。即使我对该列进行排序,如何永久编辑行?

这是显示表格的 javascript

    $(function () {
    $('#table').bootstrapTable({
        idField: 'name',
        pagination: true,
        search: true,
        url: '/gh/get/response.json/wenzhixin/bootstrap-table/tree/master/docs/data/data1/',
        columns: [{
            field: 'name',
            sortable: true,
            title: 'Name'
        }, {
            field: 'stargazers_count',
            sortable: true,
            title: 'Stars'
        }, {
            field: 'forks_count',
            sortable: true,
            title: 'Forks'
        }, {
            field: 'description',
            sortable: true,
            title: 'Description'
        }],
        onPostBody: function () {
            $('#table').editableTableWidget({editor: $('<textarea>')});
        }
    });
});

这是我的 jsfiddle:

http://jsfiddle.net/dyaskur/vxbfzke5/

顺便说一句,我当前的项目使用的是引导表而不是数据表。
我不是试图找到将数据保存到数据库的解决方案,而是将数据保存到引导表以便动态排序

【问题讨论】:

    标签: jquery twitter-bootstrap bootstrap-table


    【解决方案1】:

    您需要保存可编辑的数据,然后申请排序。当您编辑表格时,它是临时的,当您对表格进行排序时,插件会获取您存储的数据并对其进行排序。

    $(function () {
    $('#table').bootstrapTable({
        idField: 'name',
        pagination: true,
        search: true,
        url: '/gh/get/response.json/wenzhixin/bootstrap-table/tree/master/docs/data/data1/',
        columns: [{
            field: 'name',
            sortable: true,
            title: 'Name'
        }, {
            field: 'stargazers_count',
            sortable: true,
            title: 'Stars'
        }, {
            field: 'forks_count',
            sortable: true,
            title: 'Forks'
        }, {
            field: 'description',
            sortable: true,
            title: 'Description'
        }],
        onPostBody: function () {
            $('#table').editableTableWidget({editor: $('<textarea>')});
        }
    });
    
    $('table td').on('change', function(evt, newValue) {
        // do something with the new cell value 
        if (....) { 
            return false; // reject change
        }
    });
    });
    

    【讨论】:

    • 深入检查你的插件事件
    • 嗯,我不明白
    • 检查引导表事件的
    • 我必须在那里做什么?
    • 我必须检查哪里? jsfiddle 没有更新。还是你喜欢它?
    猜你喜欢
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-06
    • 2019-09-25
    • 1970-01-01
    • 2020-11-22
    相关资源
    最近更新 更多