无法将jQuery tableditor附加到我的表中

时间:2016-01-09 15:46:17

标签: php jquery jquery-plugins

我下载了jQuery tableditor但我无法使用。 我在页面中添加了JS文件:

<script src="../assets/jquery-tabledit-1.2.3/jquery.tabledit.js"></script>
    <script src="../assets/jquery-tabledit-1.2.3/jquery.tabledit.min.js"></script>
    <script>
        $('#sales_table').Tabledit({
            url: 'example.php',
            editButton: false,
            deleteButton: false,
            hideIdentifier: true,
            columns: {
                identifier: [0, 'id'],
                editable: [[2, 'firstname'], [3, 'lastname']]
            }
        });
    </script>

这是我的表:

        <table id="sales_table" border="1">
        <tr>
        <td id="firstname" name="firstname">a</td>
        <td>a</td>
        </tr>
        </table>

但什么都没发生,也无法编辑表格。 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

您对可编辑列使用了错误的索引值,并且还需要标识符列。通过调用Tableedit隐藏标识符列。

您似乎还没有引用主jquery库(至少在您提供的示例中): JQuery

有关工作示例,请参阅此处: Fiddle

如果您想更新表格并执行任何其他功能,您需要阅读文档:

Tableedit Docs

<强> HTML

<table id="sales_table" border="1">
  <thead>
    <tr>
      <td>First name</td>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td id="identifier" name="identifier">1</td> 
      <td id="firstname" name="firstname">John</td>
    </tr>
  </tbody>
</table>

<强> JQuery的

$('#sales_table').Tabledit({
  url: 'example.php',
  editButton: false,
  deleteButton: false,
  hideIdentifier: true,
  columns: {
    identifier: [0, 'id'],
    //Note that I've modified the column index values.
    editable: [[1, 'firstname'], [2, 'lastname']]
  }
});