dabory-table.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. (function($) {
  2. $.fn.table = async function(options) {
  3. };
  4. $.fn.table.lineSelect = function() {
  5. return `<select class="dabory-table-line-select">
  6. <option value="10">10 Lines</option>
  7. <option value="15">15 Lines</option>
  8. <option value="20">20 Lines</option>
  9. <option value="30">30 Lines</option>
  10. <option value="40">40 Lines</option>
  11. <option value="50">50 Lines</option>
  12. <option value="100">100 Lines</option>
  13. <option value="200">200 Lines</option>
  14. <option value="300">300 Lines</option>
  15. <option value="400">400 Lines</option>
  16. <option value="500">500 Lines</option>
  17. </select>`
  18. }
  19. $.fn.table.orderBySelect = function() {
  20. return `<div class="dabory-table-order-by-div">
  21. <select class="dabory-table-order-by-select">
  22. <option value="setup_code asc, seq_no asc">설정코드 순서</option>
  23. <option value="setup_code desc, seq_no asc">설정 코드 역순</option>
  24. </select>
  25. </div>`
  26. }
  27. $.fn.table.makePagination = function(limit, total, page = 1) {
  28. let overFlow = false
  29. const totalPage = Math.ceil( total / limit ),
  30. pageGroup = Math.ceil( page / 5 ),
  31. last_ = pageGroup * 5,
  32. first = last_ - 4
  33. last = (overFlow = last_ > totalPage) ? totalPage : last_,
  34. links = `<li class="%active% page-item"><a data-offset="%offset%" data-page="%page%" class="page-link" href="#" onclick="return false;">%datas%</a></li>`;
  35. let next = last + 1,
  36. prev = first - 1,
  37. html = '';
  38. if (page <= 5) {
  39. html += `
  40. <li class="page-item disabled" aria-disabled="true">
  41. <span class="page-link" aria-hidden="true">&laquo;</span>
  42. </li>
  43. <li class="page-item disabled" aria-disabled="true">
  44. <span class="page-link" aria-hidden="true">&lsaquo;</span>
  45. </li>
  46. `
  47. } else {
  48. html += links.co_split({active: '', offset: 0, page: 1, datas: `&laquo;`});
  49. html += links.co_split({active: '', offset: (prev - 1) * limit, page: prev, datas: `&lsaquo;`});
  50. }
  51. for (let i = first; i <= last; i++) {
  52. if ( i >= 1 && i <= totalPage ) {
  53. const active = (page === i) ? ` active ` : ``,
  54. offset = (i - 1) * limit;
  55. html += links.co_split({active: active, offset: offset, page: i, datas: i});
  56. }
  57. }
  58. if (! overFlow && ! (first + 5 > totalPage)) {
  59. html += links.co_split({active: '', offset: (next - 1) * limit, page: next, datas: `&rsaquo;`});
  60. html += links.co_split({active: '', offset: (totalPage - 1) * limit, page: totalPage, datas: `&raquo;`});
  61. } else {
  62. html += `
  63. <li class="page-item disabled" aria-disabled="true">
  64. <span class="page-link" aria-hidden="true">&rsaquo;</span>
  65. </li>
  66. <li class="page-item disabled" aria-disabled="true">
  67. <span class="page-link" aria-hidden="true">&raquo;</span>
  68. </li>
  69. `
  70. }
  71. return html
  72. };
  73. }(jQuery));