数据表编辑器不发送ID

时间:2015-10-06 20:33:16

标签: javascript json datatables

我需要更新mysql中的数据,我正在使用数据表内联编辑扩展。 我需要解决的问题是,如何发送行的id,字段的名称和单元格的值。 这是它发送的数据; 我明白了:

data[1][player_nickname]:Rafantunessdds

但我需要:

editor = new $.fn.dataTable.Editor({
        table: "#dtables",
        ajax: {
            edit: {
                type: 'GET',
                url: '<?php echo site_url(); ?>players/saveUserData'
            },
        },
        fields: [{
                label: "Nickname:",
                name: "player_nickname"
            }, {
                label: "Email:",
                name: "player_email"
            }, {
                label: "Password:",
                name: "player_password"
            },
            {
                label: "Is Admin:",
                name: "is_admin"
            },
            {
                label: "Is Moderator:",
                name: "is_moderator"
            },
            {
                label: "is Manager:",
                name: "is_manager"
            },
            {
                label: "is Premiun:",
                name: "player_premium"
            },
            {
                label: "Is banned:",
                name: "player_banned"
            },
        ]
    });

这是我的js代码:

editor = new $.fn.dataTable.Editor({
        ajax: "players/saveuserdata.php",
        table: ".dtables",
        fields: [{
                label: "Nickname:",
                name: "player_nickname"
            }, {
                label: "Email:",
                name: "player_email"
            }, {
                label: "Password:",
                name: "player_password"
            },
            {
                label: "Is Admin:",
                name: "is_admin"
            },
            {
                label: "Is Moderator:",
                name: "is_moderator"
            },
            {
                label: "is Manager:",
                name: "is_manager"
            },
            {
                label: "is Premiun:",
                name: "player_premium"
            },
            {
                label: "Is banned:",
                name: "player_banned"
            },
        ]
    });

    $('.dtables').on('click', 'tbody td:not(:first-child)', function (e) {
        editor.inline(this);
    });
    $('.dtables').DataTable({

        data: <?php echo($players) ?>,
        columns: [
            {data: 'player_id'},
            {data: 'player_nickname'},
            {data: 'player_email'},
            {data: 'player_password'},
            {data: 'is_admin'},
            {data: 'is_moderator'},
            {data: 'is_manager'},
            {data: 'player_premium'},
            {data: 'player_banned'}

        ]
    });
watch

如何发送行的ID?

1 个答案:

答案 0 :(得分:1)

使用idSrc JSON属性rom来读取/写入行的ID属性。

idSrc: "player_id"