javascript - jQuery dataTables - adding row does not work -
a lot of solutions found nothing working me. can please tell me what's wrong code?
my table like
<table id="allpermission" class=" table-striped" cellspacing="0" width="100%"> <thead> <tr> <th>permission no</th> <th>permission</th> <th>command</th> </tr> </thead> <tbody> </tbody> <tfoot> <tr> <th>permission no</th> <th>permission</th> <th>command</th> </tr> </tfoot> </table>
and java script code here
var tbl = $('#allpermission').datatable({ "processing": true, "retrieve": true, "serverside": true, "lengthmenu": [ [5, 10, 25, -1], [5, 10, 25, "all"] ], "ajax": $.fn.datatable.pipeline({ url: 'rest/showallpermissions', pages: 2 // number of pages cache }), "columns": [{ "data": "permid" }, { "data": "permissionname" }, { "data": "dt_rowid", "sortable": false, "render": function(data, type, full) { var result = ""; result = '<a class="btn btn-info btn-sm" href=/fieldforce/user/editadmin/' + full.dt_rowid + ' style="width: 58px;"' + '>' + 'edit' + '</a>' + '<a class="btn btn-danger btn-sm" href=/fieldforce/user/deleteadmin/' + full.dt_rowid + ' style="margin-left: 15px;"' + '>' + 'delete' + '</a>'; return result; } }], "deferrender": true, "scrolly": "250px" }); $('#addperm').submit(function(e) { e.preventdefault(); $('#loadinggif').css({ "display": "block" }); $('#formbody').css({ "display": "none" }); // ajax submition $.ajax({ url: "/fieldforce/administration/rest/addpermission", type: "post", data: $(this).serialize(), success: function(data, status, xhr) { $('#loadinggif').css({ "display": "none" }); // $('#addpermission').modal('toggle'); $('#messagebody').html("success"); tbl.row.add({ "permid": '9', "permissionname": 'admin', "dt_rowid": '8' }).draw(); }, error: function(jqxhr, textstatus, errorthrown) { $('#messagebody').html("server error"); } }); });
i using jquery version jquery-1.11.1.min , datatable version //cdn.datatables.net/1.10.7/js/jquery.datatables.min.js tia
see example
$(function(){ var tbl = $('#allpermission').datatable(); tbl.row.add(['9','admin','8']).draw(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="//cdn.datatables.net/1.10.7/js/jquery.datatables.min.js"></script> <link href="//cdn.datatables.net/1.10.7/css/jquery.datatables.min.css" rel="stylesheet"/> <table id="allpermission"> <thead> <tr> <th>permid</th> <th>permissionname</th> <th>dt_rowid</th> </tr> </thead> </table>
Comments
Post a Comment