Tabledit没有发送帖子动作

问题描述 投票:1回答:2

我最近在一个页面中插入了tabledit,我跟着几个例子,但是所有插件都没有发布,不发布任何内容都是空的,我不知道如何让帖子工作你可以帮我一个忙吗?

简单的脚本:

     <table class='table'>
  <thead>
    <tr>
      <th>Id</th>
      <th>Firstname</th>
      <th>Lastname</th>
      <th>Email</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td>Doe</td>
      <td>Doe</td>
      <td>[email protected]</td>
    </tr>
  </tbody>
</table>
<script>
  $('.table').Tabledit({
    url: 'index.php',
    columns: {
      identifier: [0, 'id'],
      editable: [
        [1, 'col1'],
        [2, 'col2'],
        [3, 'col3']
      ]
    }
  });
</script>

一切都很简单它工作我收到按钮但保存和删除ajax中的帖子但没有没有formdata的字段,我该怎么办?

javascript bootstrap-4 tabledit
2个回答
0
投票

您需要向相关单元格添加一些代码:

<td class='tabledit-view-mode' style='cursor: pointer; background-color: #DEE1E8;'>
<span class='tabledit-span' style='display: inline;'>YOUR CELL DATA</span>
<input name='VAR_NAME' disabled='' class='tabledit-input form-control input-sm' style='display: none;' type='text' value='YOUR CELL DATA'></td>

当您单击它时,Tabledit会将显示更改为输入,这样您就可以获得变量。


0
投票

您只缺少Tabledit定义中的处理程序声明。

documentation中有一些例子。

我已经为你添加了它们。

$(document).ready(function() {

    $('.table').Tabledit({
        url: 'index.php',
        columns: {
            identifier: [0, 'Id'],
            editable: [
                [1, 'Firstname'],
                [2, 'Lastname'],
                [3, 'Email']
            ]
        },
        onSuccess: function(data, textStatus, jqXHR) {
            // deal with success there
        },
        onFail: function(jqXHR, textStatus, errorThrown) {
            // deal with errors there
        },
        onAjax: function(action, serialize) {
            // open your xhr here 
            console.log("on Ajax");
            console.log("action : ", action);
            console.log("data : ", serialize);
        }
    });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/jquery.tabledit.min.js"></script>
<table class='table'>
   <thead>
      <tr>
         <th>Id</th>
         <th>Firstname</th>
         <th>Lastname</th>
         <th>Email</th>
      </tr>
   </thead>
   <tbody>
      <tr>
         <td>1</td>
         <td>Doe</td>
         <td>Doe</td>
         <td>[email protected]</td>
      </tr>
   </tbody>
</table>
© www.soinside.com 2019 - 2024. All rights reserved.