繁体   English   中英

带有JEditable的jQuery DataTables

[英]jQuery DataTables with 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>

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

当使用版本2+时(因为写入时没有下载在网站上,但最新的稳定版似乎是2.0.7,只是从源代码复制文件......),你可以采用这种方法,如Jovan(创建者)在这个错误报告中指出

var currentKey = '';

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

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

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

我会尝试这个

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM