2011-07-02 50 views
0

我試圖用jQuery和它的插件DataTables(http://www.datatables.net/release-datatables/examples/api/editable.html)來創建一個可編輯的表格。需要在jQuery(DataTables插件)中編輯表格的幫助

這是我的代碼到目前爲止。它的頂部部分通過在一個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... 

回答

0

我看到美國的例子來初始化表所示:

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

話雖這麼說,我還沒有得到它尚未擦出火花。

0

這是對我工作的例子:

$('#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: '' } 
      ], 
});