Advertisement
ridhwanfaris

contoh datatable async

Oct 27th, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 2.37 KB | None | 0 0
  1. function getUserList(){
  2. var html = "";
  3.    
  4.     html += "<table id='datatable-buttons' class='table table-striped table-bordered dt-responsive nowrap'";
  5.     html += "style='border-collapse: collapse; border-spacing: 0; width: 100%;'>";
  6.     html += "<thead>";
  7.     html += "<tr>";
  8.     html += "<th>Book Code</th>";
  9.     html += "<th>Book Name</th>";
  10.     html += "<th>Book Creator</th>";
  11.     html += "<th>Book Publisher</th>";
  12.     html += "<th>Book Quantity</th>";
  13.     html += "<th>Book Receive Date</th>";
  14.     html += "<th>Book Note</th>";
  15.     html += "<th>Book Category</th>"
  16.     html += "</tr>";
  17.     html += "</thead>";
  18.     html += "</table>";
  19.    
  20.     $("#bookListDT").html(html);
  21.    
  22.    
  23.      $("#datatable-buttons").DataTable({
  24.          dom: 'Bfrtip',
  25.          ajax   : {
  26.                 type        : "GET",
  27.                 url     : "getBookList",
  28.                 dataSrc : function (json) {
  29.                     var return_data = new Array();
  30.                     for(var i=0;i<json.length; i++){
  31.                         return_data.push({
  32.                             'bookCode'          : json[i].bookCode,
  33.                             'bookName'          : json[i].bookName,
  34.                             'bookCreator'       : json[i].bookCreator,
  35.                             'bookPublisher'     : json[i].bookPublisher,
  36.                             'bookQuantity'      : json[i].bookQuantity,
  37.                             'bookReceiveDate'   : json[i].bookReceiveDate,
  38.                             'bookNote'          : json[i].bookNote,
  39.                             'booksCategory'     : json[i].booksCategory.categoryName,
  40.                         })
  41.                     }
  42.                     return return_data;
  43.                 }
  44.             },
  45.                
  46.             columns : [
  47.                 {data: 'bookCode'},
  48.                 {data: 'bookName'},
  49.                 {data: 'bookCreator'},
  50.                 {data: 'bookPublisher'},
  51.                 {data: 'bookQuantity'},
  52.                 {data: 'bookReceiveDate'},
  53.                 {data: 'bookNote'},
  54.                 {data: 'booksCategory'}
  55.             ],lengthChange:!1,buttons:[
  56.                 {
  57.                     extend: 'print',
  58.                     exportOptions: {
  59.                 columns: [ 0, 1, 2, 3, 4, 5, 6 ]
  60.             }
  61.                 },
  62.                 {
  63.                     extend: 'excel',
  64.                     exportOptions: {
  65.                 columns: [ 0, 1, 2, 3, 4, 5, 6 ]
  66.             }
  67.                 },
  68.                 {
  69.                     extend: 'csv',
  70.                     exportOptions: {
  71.                 columns: [ 0, 1, 2, 3, 4, 5, 6 ]
  72.             }
  73.                 },
  74.                 'colvis'
  75.             ]
  76.         }).buttons().container().appendTo("#datatable-buttons_wrapper .col-md-6:eq(0)");
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement