【问题标题】:Editor_dataTables - Inline Edit for multiple tablesEditor_dataTables - 多个表的内联编辑
【发布时间】:2015-03-17 15:35:05
【问题描述】:

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

$(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>

【问题讨论】:

  • 为其他表选择一个新的变量名而不是编辑器。

标签: javascript php html


【解决方案1】:

这样试试

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

【讨论】:

  • 干得好,谢谢。这里也是 ---> $('#example2').on( 'click', 'tbody td', function () { editor2.inline( this ); } );
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-30
  • 2014-07-15
  • 2010-10-02
相关资源
最近更新 更多