javascript - Editor_dataTables - 多个表的内联编辑

标签 javascript php html

我正在使用数据表编辑器,但内联编辑不适用于所有表。
只有第二个表允许内联编辑。 我如何才能从同一页面上的所有表格中进行内联编辑? 两个表都填充了数据。 是 变量编辑器;//在示例中使用全局提交和返回数据渲染

$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
    ajax: "../php/staff2.php",
     "bProcessing": true,
    "bServerSide": true,
    table: "#example1",
    fields: [ {
            label: "subject:",
            name: "subject"
        }, {
            label: "ApplicationDate:",
            name: "ApplicationDate"
        }, {
            label: "PreferedPaymentDate:",
            name: "PreferedPaymentDate"
        }, {
            label: "Ledger:",
            name: "Ledger"
        }, {
            label: "BranchName:",
            name: "BranchName"
        }, {
            label: "AppNumber:",
            name: "AppNumber",
        }
    ]
} );

// Activate an inline edit on click of a table cell
    $('#example1').on( 'click', 'tbody tb', function () {
editor.inline( this );
    } );

$('#example1').DataTable( {
    dom: "Tfrtip",
    "searching": false,
    "bInfo" : false,
    "bPaginate": false,
    "bSort": false,
    "bVisible": false,
    ajax: "../php/staff2.php",
    columns: [
        { data: null, defaultContent: '', orderable: false },
        { data: "subject" },
        { data: "ApplicationDate" },
        { data: "PreferedPaymentDate" },
        { data: "Ledger" },
        { data: "BranchName" },
        { data: "AppNumber", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },

    ],
    order: [ 1, 'asc' ],
    tableTools: {
        sRowSelect: "os",
        sRowSelector: 'td:first-child',
        aButtons: [
            { sExtends: "editor_create", editor: editor },
            { sExtends: "editor_edit",   editor: editor },
            { sExtends: "editor_remove", editor: editor }
        ]
    }
} )
                     } );

      $(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
    ajax: "../php/staff2.php",
    table: "#example2",
    "bProcessing": true,
    "bServerSide": true,
    fields: [ {
            label: "subject:",
            name: "subject"
        }, {
            label: "ApplicationDate:",
            name: "ApplicationDate"
        }, {
            label: "PreferedPaymentDate:",
            name: "PreferedPaymentDate"
        }, {
            label: "Ledger:",
            name: "Ledger"
        }, {
            label: "BranchName:",
            name: "BranchName"
        }, {
            label: "AppNumber:",
            name: "AppNumber",
        }
    ]
          } );

// Activate an inline edit on click of a table cell
     $('#example2').on( 'click', 'tbody td', function () {
editor.inline( this );
     } );

$('#example2').DataTable( {
    dom: "Tfrtip",
    "searching": false,
    "bInfo" : false,
    "bPaginate": false,
    "bSort": false,
    "bVisible": false,
    ajax: "../php/staff2.php",
    columns: [
        { data: null, defaultContent: '', orderable: false },
        { data: "subject" },
        { data: "ApplicationDate" },
        { data: "PreferedPaymentDate" },
        { data: "Ledger" },
        { data: "BranchName" },
        { data: "AppNumber", render: $.fn.dataTable.render.number( ',', '.', 0, '$' ) },

    ],
    order: [ 1, 'asc' ],
    tableTools: {
        sRowSelect: "os",
        sRowSelector: 'td:first-child',
        aButtons: [
            { sExtends: "editor_create", editor: editor },
            { sExtends: "editor_edit",   editor: editor },
            { sExtends: "editor_remove", editor: editor }
        ]
    }
} );
              } );

<div class="container">
    <section>
        <table id="example1" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>
                    <th>First name</th>
                    <th>Last name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th width="18%">Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
        </table>

<div class="container">
    <section>   
        <table id="example2" class="display" cellspacing="0" width="100%">
            <thead>
                <tr>
                    <th>

                    <th>First name</th>
                    <th>Last name</th>
                    <th>Position</th>
                    <th>Office</th>
                    <th width="18%">Start date</th>
                    <th>Salary</th>
                </tr>
            </thead>
        </table>

最佳答案

这样试试

editor1 = new $.fn.dataTable.Editor( { ....for example1 table
editor2 = new $.fn.dataTable.Editor( { ....for example2 table

关于javascript - Editor_dataTables - 多个表的内联编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29103290/

相关文章:

javascript - 不允许更改现有属性的可扩展对象?

php - echo Javascript window.location.href 不工作

c++ - 为什么 C++ 不像 HTML/HTML5 那样移动到 'unversioned model'?

javascript - 后台脚本中的 Chrome 扩展程序 : using document. querySelector

javascript - 使用共享工具提示时,Highcharts 柱形图在单击时返回不正确的系列索引

javascript - 如何发布我在 Rails 中看到的一些问题的 jsfiddle 示例?

php - Android 向服务器发送 JSON 对象时出现问题

php - FullCalendar/JSON 事件源问题

html - Bootstrap 中的凸起段?

html - 社交媒体按钮不起作用