Advertisement
Guest User

fungsi error beserta js

a guest
Apr 24th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. //-------------------Control-------------------------------------------------
  2.  
  3. public function index() {
  4. Template::set('toolbar_title', 'Manage Employees List');
  5. Template::render();
  6. }
  7.  
  8. public function pagination() {
  9. $this->employees_list_model->search_document();
  10. }
  11.  
  12. //--------------------Model------------------------------------------------
  13.  
  14. public function search_document() {
  15. $input = array('dataperpage', 'query', 'curpage');
  16. foreach ($input as $val)
  17. $$val = $this->input->post($val);
  18.  
  19. $query = $this->db->escape_like_str($query);
  20. $where = "'no_badge' LIKE '%{$query}%' OR 'position' LIKE '%{$query}%'";
  21.  
  22. $query = $this->db->query("SELECT COUNT('id') AS 'HASIL' FROM bf_employees_list WHERE
  23.  
  24. $where");
  25. $total = $query->row()->HASIL;
  26. $npage = ceil($total / $dataperpage);
  27.  
  28. $start = $curpage * $dataperpage;
  29. $end = $start + $dataperpage;
  30. $query = $this->db->query("SELECT 'no_badge', 'position', 'status' FROM bf_employees_list
  31.  
  32. WHERE $where LIMIT $start, $dataperpage");
  33. $hasil = array(
  34. 'data' => array(),
  35. 'pagination' => '',
  36. 'numpage' => $npage - 1,
  37. );
  38. if ($query->num_rows() > 0) {
  39. foreach ($query->result() as $row) {
  40. $hasil['data'][] = array(
  41. 'judul' => $row->no_badge,
  42. 'pengarang' => $row->position,
  43. 'tahun' => $row->status
  44. );
  45. }
  46. }
  47.  
  48. $hasil['pagination'] .= '<ul>
  49. <li class="'. ($curpage == 0 ? 'disabled' : '') .'" onclick="return Document.prevPage
  50.  
  51. ()"><a href>&laquo;</li>';
  52. for ($i = 1; $i <= $npage; $i++) {
  53. $hasil['pagination'] .= '<li class="' . ($curpage == ($i - 1) ? 'active' : '') . '"
  54.  
  55. onclick="return Document.setPage(' . ($i - 1) .')"><a href>' . $i . '</a></li>';
  56. }
  57. $hasil['pagination'] .= '<li class="' . ($curpage == $npage - 1 ? 'disabled' : '') . '"
  58.  
  59. onclick="return Document.nextPage()"><a href>&raquo;</a></li>
  60. </ul>';
  61.  
  62. echo json_encode($hasil, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
  63. }
  64.  
  65. //--------------------Views------------------------------------------------
  66. <script>
  67. var Document = {
  68. param: {
  69. dataperpage: 10, // jumlah data per halaman
  70. query: '',
  71. curpage: 0,
  72. numpage: 0
  73. },
  74. url: "<?=base_url().'/admin/employees/employees_list/'?>",
  75. search: function() {
  76. this.param.query = $('#query').val();
  77. this.param.curpage = 0;
  78. this.loadData();
  79. return false;
  80. },
  81. setPage: function(n) {
  82. this.param.curpage = n;
  83. this.loadData();
  84. return false;
  85. },
  86. prevPage: function() {
  87. if (this.param.curpage > 0) {
  88. this.param.curpage--;
  89. this.loadData();
  90. }
  91. return false;
  92. },
  93. nextPage: function() {
  94. if (this.param.curpage < this.param.numpage) {
  95. this.param.curpage++;
  96. this.loadData();
  97. }
  98. return false;
  99. },
  100. loadData: function() {
  101. $.ajax({
  102. url: Document.url,
  103. type: 'POST',
  104. dataType: 'json',
  105. data: jQuery.param(Document.param),
  106. success: function(d) {
  107. $('#pagination').html(d.pagination);
  108. Document.param.numpage = d.numpage;
  109. var t = '', dt = {};
  110. for (var i = 0; i < d.data.length; i++) {
  111. dt = d.data[i];
  112. t += '<tr><td>' + dt.judul +'</td>' +
  113. '<td>' + dt.pengarang + '</td>' +
  114. '<td>' + dt.tahun + '</td></tr>';
  115. }
  116. $('#document-data').html(t); // id dari tbody tabel data
  117. }
  118. });
  119. }
  120. }
  121.  
  122. $(document).ready(function() {
  123. Document.search();
  124. });
  125. </script>
  126.  
  127. <div class="admin-box">
  128. <h3>Employees List</h3>
  129.  
  130. <form class="form-inline">
  131. <input type="text" name="query" id="query" class="input-large"> &nbsp;
  132. <button class="btn" onclick="return Document.search()"><i class="icon-search"></i>
  133.  
  134. Cari</button>
  135. </form>
  136. <hr>
  137. <table class="table table-bordered table-condensed table-striped">
  138. <thead>
  139. <tr>
  140. <th>Judul</th>
  141. <th>Pengarang</th>
  142. <th>Tahun</th>
  143. </tr>
  144. </thead>
  145. <tbody id="document-data">
  146. <tr>
  147. <td></td>
  148. <td></td>
  149. <td></td>
  150. </tr>
  151. </tbody>
  152. </table>
  153. <hr>
  154. <div class="pagination pagination-centered pagination-medium" id="pagination">
  155.  
  156. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement