【问题标题】:Send all fields values to server with bootstrap-table editable plugin使用引导表可编辑插件将所有字段值发送到服务器
【发布时间】:2023-03-06 10:38:01
【问题描述】:

我正在使用带有 x-editabel 插件的引导表。该表有 3 个字段,但只有一个是可编辑的。我需要将所有字段发送到服务器脚本,而不仅仅是可编辑字段。我使用的代码如下:

$('#table-result').bootstrapTable({
 columns: [
    [{
       field: 'Network Domain',
       title: 'Network domain'
      }, {
       field: 'Service Provider',
       title: 'Service provider'
      }, {
       field: 'Category',
       title: 'Category',
       editable: {
         url: ajaxurl,
         ajaxOptions: {
           type: 'get',
           dataType: 'json'
         },
         success: function(response, newValue) {
          /* some code here */
         },
         type: 'select',
         title: 'Select category',
         placement: 'left',
         emptytext: 'empty text',
         source: [
            {value: 'cat1', text: 'cat1'},
            {value: 'cat2', text: 'cat2'}
         ]
      }],
});

这是 HTML

<table class="table table-striped table-bordered table-hover"
    id="table-result"
    data-height="800"
    data-page-list="[5, 10, 20, 50, 100, 200]"
    data-pagination="true"
    data-page-number="1"
    data-page-size="10"
    data-search="false"
    data-side-pagination="client"
    data-show-columns="true"
    data-show-export="true"
    data-sort-name="Category"
    data-sort-order="desc"
    data-toolbar="#toolbar"
    >
</table>

表格数据来自 ajax(没问题:它正在工作)。

我需要将所有字段(不仅是类别字段)发送到 ajax 脚本,该脚本将对所选类别字段执行更改。我无法为每个表格行定义和使用 pk,因为单击可编辑字段时需要执行的操作需要所有字段。 我想使用 x-editable 的“参数”选项,但我不知道如何告诉它我正在编辑的行的当前值。

你有什么建议吗? TIA

附: 抱歉,如果我无法以“可理解”的形式解释问题,但英语不是我的主要语言。

【问题讨论】:

    标签: bootstrap-table


    【解决方案1】:

    好的。我解决了这个问题。

    从可编辑中删除了 ajax 部分:

    {
      url: ajaxurl,
      ajaxOptions: {
      type: 'get',
      dataType: 'json'
    },
    success: function(response, newValue) {
       /* some code here */
    },   
    

    稍后在代码中添加为事件:

    $('#table-result').on('editable-save.bs.table', function(e, field, row, oldValue, $el){
        //row.oldCategory = oldValue;
        //console.log(row);
        $.ajax({
            data: {
                'action': 'update',
                'Network Domain': row["Network Domain"],
                'Service Provider': row["Service Provider"],
                'Category': row["Category"],
                'oldCategory': oldValue
            },
            dataType: 'json',
            url: '$ajax_action_url'
        }).done(function(response) {
            // If successful
           console.log(response);
        }).fail(function(jqXHR, textStatus, errorThrown) {
            // If fail
            console.log(textStatus + ': ' + errorThrown);
        });  
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多