簡體   English   中英

需要 jQuery 中可編輯表的幫助(DataTables 插件)

[英]need help with editable tables in jQuery ( DataTables plugin )

我正在嘗試使用 jQuery 及其插件 DataTables ( http://www.datatables.net/release-datatables/examples/api/editable.ZFC35FDC70D5FC69D269883A822C7A.EZ可編輯表)

到目前為止,這是我的代碼。 通過在 DIV 中使用 js 數組中的數據生成一個表,它的頂部效果很好。

然而,我還需要這個表是可編輯的。 我找到了它的示例代碼(見底部),但有點不知道如何將它應用到我的表中?

有任何想法嗎? 謝謝!

$(document).ready(function() {

            $('#dynamic').html( '<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"></table>' );
            /// create a table within the '#dynamic' DIV

            $('#example').dataTable( {
                "aaData": numbarr,     /////// takes data from the 'numbarr' js array.
                "aoColumns": [
                    { "sTitle": "Country&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" },   //// column names
                    { "sTitle": "Number&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" },
                    { "sTitle": "Tariff ID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" },
                    { "sTitle": "Customer Acc&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" },
                    { "sTitle": "Customer Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" },
                    { "sTitle": "Payment Terms&nbsp;&nbsp;" },
                    { "sTitle": "Payout/Call&nbsp;&nbsp;" },
                    { "sTitle": "Payout/Min&nbsp;&nbsp;" },
                ]
            } );

            ///////////////////////////// the code above workd fine!


            ////////////////// this code was taken from an example, not sure how to connect it with my table...
            $('td', oTable.fnGetNodes()).editable( '../examples_support/editable_ajax.php', {
                "callback": function( sValue, y ) {
                    var aPos = oTable.fnGetPosition( this );
                    oTable.fnUpdate( sValue, aPos[0], aPos[1] );
                },
                "submitdata": function ( value, settings ) {
                    return {
                        "row_id": this.parentNode.getAttribute('id'),
                        "column": oTable.fnGetPosition( this )[2]
                    };
                },
                "height": "12px"
            } );
            ////////////////// this code was taken from an example, not sure how to connect it with my table...

我用過這個插件http://square-bracket.com/openjs

我看到的示例狀態初始化您的表,如:

$('#example').dataTable(options).makeEditable(options);

話雖如此,我還沒有讓它工作。

這是一個對我有用的例子:

$('#tblDataTable2').dataTable({

    "bJQueryUI": true,
    "sPaginationType": "full_numbers",
    "aaSorting": [[ 0, "asc" ]],
    "aoColumnDefs": [
        { "sClass": "center", "aTargets": [ 0, 1 ] }
    ]
}).makeEditable({
    sAddURL:    "Setting?operation=create",
    sUpdateURL: "Setting?operation=update",
    "aoColumns": [
                { placeholder: '' },
                { placeholder: '' }
            ],
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM