简体   繁体   English

使用jEditable,jQuery和DataTables更新表中的单元格

[英]Updating cells in table using jEditable, jQuery and DataTables

I am very new to using DataTables as well as jQuery. 我对使用DataTables和jQuery非常陌生。

I am trying to display a table and let the user edit the cells and update the values in the MySQL database. 我试图显示一个表,让用户编辑单元格并更新MySQL数据库中的值。

I don't really understand what the sValue is used for/represents either. 我也不很清楚sValue用于/表示什么。

This is my code so far, keeping in mind that I have linked the jeditable.js file. 到目前为止,这是我的代码,请记住,我已经链接了jeditable.js文件。

$(document).ready(function() {
    /* Init DataTables */
    var oTable = $('#parentEditTable').dataTable({
        "columns": [
            {
                "data": "ParentId"
            }, {
                "data": "Name"
            }],
        "order": [[0, 'asc']],
        "processing": true,
        "serverSide": true,
        "responsive": true,

        "ajax": {
            url: 'processEditParent.php',
            type: 'POST'
        }
    });

    oTable.$('#parentEditTable').editable('processEditParent.php', {

        "callback": function( sValue, y ) {
            var aPos = oTable.GetPosition( this );
            oTable.upload( sValue, aPos[0], aPos[1] );
        },
        "submitdata": function ( value, settings ) {
            return {
                "row_id": this.parentNode.getAttribute('ParentId'),
                "column": oTable.fnGetPosition(this )[2]
            };

        },
        "height": "14px",
        "width": "100%"
    } );
} );

Any help at all would be appreciated. 任何帮助将不胜感激。

I managed to make it work using examples from http://kingkode.com/free-datatables-editor-alternative/ and some of my own code, feel free to comment or ask any questions if you need any help. 我设法使用http://kingkode.com/free-datatables-editor-alternative/中的示例以及我自己的一些代码来使其工作,如果需要任何帮助,请随时发表评论或提出任何问题。

Instead of creating a dataSet with static variables, I did a DB query and returned the results as an array and set that array as the dataSet in the dataTable function. 我没有使用静态变量创建dataSet,而是进行了数据库查询,并将结果作为数组返回,并将该数组设置为dataTable函数中的dataSet。

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

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