Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 544.9k

JQuery Datatable

May 29 2021 4:10 PM
Hi
 
I have below DataTable . I want to use Sorting,Pagelength like settings Centralised thru Class so that it can be used on all DataTables, With the below code i have to write it on every Index.
  1. $(document).ready(function () {  
  2. $("#tblLocation").dataTable({  
  3. ajax: {  
  4. type: "get",  
  5. url: "/Location/List",  
  6. dataType: "json",  
  7. dataSrc: ""  
  8. },  
  9. paging: true,  
  10. sort: true,  
  11. pageLength: 10,  
  12. searching: true,  
  13. columns: [  
  14. 'data''Id' },  
  15. 'data''Description' },  
  16. 'data''IsActive' },  
  17. {  
  18. "defaultContent"'<button id="btnEdit" type="submit"><i class="fa fa-pencil"></i></button>'  
  19. }  
  20. // <td><p data-placement="top" data-toggle="tooltip" title="Edit"><button class="btn btn-primary btn-xs" data-title="Edit" data-toggle="modal" data-target="#edit" ><span class="glyphicon glyphicon-pencil"></span></button></p></td>  
  21. //<td><p data-placement="top" data-toggle="tooltip" title="Delete"><button class="btn btn-danger btn-xs" data-title="Delete" data-toggle="modal" data-target="#delete" ><span class="glyphicon glyphicon-trash"></span></button></p></td>  
  22. ]  
  23. });  
  24. $('body').on('click''[id*=btnEdit]'function () {  
  25. var data = $(this).parents('tr').find('td');  
  26. var id = data.eq(0).html();  
  27. var description = data.eq(1).html();  
  28. $('[id*=txtId]').val(id);  
  29. $('[id*=txtDescription]').val(description);  
  30. $("#btnAdd").hide();  
  31. $(".modal-title").html("Update");  
  32. $("#btnUpdate").show();  
  33. $('#myModal').modal("show");  
  34. });  
  35. });  
Thanks

Answers (4)