带有JEditable的jQuery DataTables

时间:2012-02-01 23:10:20

标签: jquery datatables jeditable

我有一个使用jEditable的DataTable,以便用户可以修改第3列中保存的值。用户只能编辑第3列值但是查看AJAX帖子时它没有发送“ID”,这是第1列中保存的值。查看Firebug我在POST期间看到以下内容:

column  2

id  district

row_id  null

value   new text

这是我的代码,我想在RETURN部分添加一行,以便它返回第一列[0]的值(this)?不知道如何做到这一点,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>

3 个答案:

答案 0 :(得分:1)

当使用版本2+时(由于写入时间没有下载在网站上,但最新的稳定版似乎是2.0.7,只需从源代码复制文件......),你可以采用这种方法,正如Jovan(创作者)在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)

找出问题,只需将变量设置为第1列[0]中的值,然后在POST中返回值。 var id2 = oTable.fnGetData(aPos2 [0]);

答案 2 :(得分:0)

我会尝试这个

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

观看此对象的控制台,它会显示您可以访问的所有内容。