2012-02-01 52 views
0

我有一個DataTable使用jEditable,以便用戶可以修改第三列中保存的值。用戶只能編輯第3個值,但看AJAX發佈它未發送的「ID」,這是我看到一個貼子在接下來的第1列中保存的值看着螢火蟲:jQuery DataTables JEditable

column 2 

id district 

row_id null 

value new text 

這裏是我的代碼,我想添加一行到RETURN部分,以便它返回(this)的第一列[0]的值?不知道如何做到這一點,很新的JavaScript ...

<script> 
$(document).ready(function() { 
/* Init DataTables */ 
var oTable = $('#district').dataTable(); 

/* Apply the jEditable handlers to the table */ 
$('#district', oTable.fnGetNodes()).editable('editable_ajax.php', { 
    "callback": function(sValue, y) { 
     var aPos = oTable.fnGetPosition(this); 
     oTable.fnUpdate(sValue, aPos[0], aPos[1], aPos[2]); 
    }, 
    "submitdata": function (value, settings) { 
     return { 
      "row_id": this.parentNode.getAttribute('id'), 
      "column": oTable.fnGetPosition(this)[2] 
     }; 
    }, 
    "height": "14px" 
}); 
}); 
</script> 
+0

找出問題,只需將一個變量設置爲列1 [0]中的值,然後在POST中返回該值。 'var id2 = oTable.fnGetData(aPos2 [0]); ' – xXPhenom22Xx 2012-02-02 19:57:26

回答

0

我會嘗試這個

"submitdata": function (value, settings) { 
    console.log(this); 
    return { 
     "row_id": this.parentNode.getAttribute('id'), 
     "column": oTable.fnGetPosition(this)[2] 
    }; 
}, 

,看你的控制檯,這個對象,它會告訴你,你有機會獲得一切至。

1

當使用2+版本(作爲寫作時間沒有下載是在網站上公佈,但最新的穩定似乎是2.0.7,只需從源文件複製...),你可以做到這一點如約萬(創建者)在this bug report指出:

var currentKey = ''; 

$('#example').dataTable().makeEditable({ 

    fnOnEditing: function(input) { 
     currentKey = input.parents("tr").children("td:first").text(); 
     return true; 
    }, 

    oUpdateParameters: { 
     key: function() { 
      return currentKey; 
     } 
    } 
}); 
1

想出問題,只需一個變量設置爲在第1列的值[0],然後返回在POST的值。 var id2 = oTable.fnGetData(aPos2 [0]);