Jquery Datatables fnAddData与mRender

时间:2013-12-20 14:58:02

标签: jquery datatables

我有一个jQuery数据表,它从远程源中提取数据:

{"aaData":["id": "1", "DT_RowId": "1", "firm-firmname": "name", "rolename": "somerole", "activeFlag": "1"]}

在初始渲染过程中,我添加了一些额外的列(左侧是复选框,右侧是“action”列,允许删除和编辑等)。功能都很好(对不起,如果这是凌乱的)。

以下是aoColumns:

"aoColumns": [
            {"sTitle": null, "sWidth": "2%", "bSortable": false, "mData": null, "mRender": function (data, type, full) {
              return "<input id='selected_col" + full.id + "' onchange='check_checkbox(" + full.id + ", \"" + full.rolename + "\")' name='selected_cols[]' type='checkbox' value='" + full.id + "'>";
            }},
            {"sTitle": "Firm Name", "sWidth": "20%", "mData": "firm-firmname"},
            {"mData": "rolename", "sTitle": "Role Name", "sWidth": "20%"},
            {"mData": "activeflag", "sTitle": "Active", "sWidth": "10%", "mRender": function(data, type, full) { 
              if(data == 1) {
                return "Yes";
              }
              else {
                return "No";
              }
            }},
            {"mData": null, "sTitle": "Actions", "sWidth": "5%", "bSortable": false, "mRender": function( data, type, full) {
              return '<span class="glyphicon glyphicon-user" style="cursor:pointer" title="Manage Role Users"></span>&nbsp;&nbsp;<a href="#modal-dialog" data-toggle="modal" role="button"><span class="glyphicon glyphicon-pencil" style="cursor: pointer" title="Edit" onclick="load_edit(\'' + full.id + '\', \'' + full.rolename + '\', \'' + full.activeflag + '\')"></span></a>&nbsp;&nbsp;<a href="#modal-dialog-delete" role="button" data-toggle="modal"><span class="glyphicon glyphicon-trash" onclick="role_delete(\'single\', \'' + full.id + '\', \'' + full.rolename + '\', this)" style="cursor: pointer" title="Delete"></span></a>';
            }}
          ]

当我尝试在行中添加或更新数据时出现问题。我一直收到有关未找到特定列的警报错误。根据文档,我可以使用mData对象,但我找不到其中一个要创建的示例。我尝试了一些不同的东西,我认为一旦我有了添加的解决方案,它将继续进行更新。希望有人可以告诉我这里我做错了什么:

//blah blah ajax call to add row, returns json {"error": false, "newid": 38}

            var oldid = $('#role_id').val();
            var role_name = $('#role_name');
            var active_flag = $('#active_flag');
            oTable.fnAddData([data.newid, data.newid, 'sessionvar', role_name, active_flag]);

如果有人需要其他信息,请告诉我们。提前感谢您的帮助。

0 个答案:

没有答案