Created
December 16, 2013 04:05
-
-
Save siteslave/7982125 to your computer and use it in GitHub Desktop.
[ประกอบหนังสือ Bootstrap]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Bootstrap 101 Template</title> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <link href="../assets/css/bootstrap.min.css" rel="stylesheet"> | |
| <script src="../assets/js/jquery.js"></script> | |
| <script src="../assets/js/bootstrap.min.js"></script> | |
| <script src="dist/jquery.paging.min.js"></script> | |
| </head> | |
| <body style="padding: 100px;"> | |
| <table class="table table-striped" id="tbl_list"> | |
| <thead> | |
| <tr> | |
| <th>รหัส</th> | |
| <th>ชื่อหน่วยบริการ</th> | |
| <th>ประเภท</th> | |
| </tr> | |
| </thead> | |
| <tbody></tbody> | |
| </table> | |
| <ul class="pagination" id="paging"></ul> | |
| <script> | |
| var paging_format = function(type){ | |
| switch (type) { | |
| case 'block': | |
| if (!this.active) | |
| return '<li class="disabled"><a href="">' + this.value + | |
| '</a></li>'; | |
| else if (this.value != this.page) | |
| return '<li><a href="#' + this.value + '">' + this.value + | |
| '</a></li>'; | |
| return '<li class="active"><a href="#">' + this.value + | |
| '</a></li>'; | |
| case 'right': | |
| case 'left': | |
| if (!this.active) { | |
| return ""; | |
| } | |
| return '<li><a href="#' + this.value + '">' + this.value + | |
| '</a></li>'; | |
| case 'next': | |
| if (this.active) { | |
| return '<li><a href="#' + this.value + '">»</a></li>'; | |
| } | |
| return '<li class="disabled"><a href="">»</a></li>'; | |
| case 'prev': | |
| if (this.active) { | |
| return '<li><a href="#' + this.value + '">«</a></li>'; | |
| } | |
| return '<li class="disabled"><a href="">«</a></li>'; | |
| case 'first': | |
| if (this.active) { | |
| return '<li><a href="#' + this.value + '"><</a></li>'; | |
| } | |
| return '<li class="disabled"><a href=""><</a></li>'; | |
| case 'last': | |
| if (this.active) { | |
| return '<li><a href="#' + this.value + '">></a></li>'; | |
| } | |
| return '<li class="disabled"><a href="">></a></li>'; | |
| case 'fill': | |
| if (this.active) { | |
| return '<li class="disabled"><a href="#">...</a></li>'; | |
| } | |
| } | |
| return ""; // return nothing for missing branches | |
| }; | |
| var get_total = function(callback) { | |
| $.ajax({ | |
| url: 'http://localhost/hospitals3.php', | |
| type: 'GET', | |
| dataType: 'jsonp', | |
| data: { }, | |
| success: function(data){ | |
| if(data.ok){ | |
| if(data !== null){ | |
| callback(null, data.total); | |
| }else{ | |
| callback('ไม่พบข้อมูล', null); | |
| } | |
| }else{ | |
| callback('เกิดข้อผิดพลาด', null); | |
| } | |
| }, | |
| error: function(xhr, status){ | |
| callback('Error: [' + xhr.status + '] ' + xhr.statusText, null); | |
| } | |
| }); | |
| }; | |
| var get_list = function(start, stop, callback) { | |
| $.ajax({ | |
| url: 'http://localhost/hospitals2.php', | |
| type: 'GET', | |
| dataType: 'jsonp', | |
| data: { | |
| start: start, | |
| stop: stop | |
| }, | |
| success: function(data){ | |
| if(data.ok){ | |
| if(data !== null){ | |
| callback(null, data.rows); | |
| }else{ | |
| callback('ไม่พบข้อมูล'); | |
| } | |
| }else{ | |
| callback('เกิดข้อผิดพลาด'); | |
| } | |
| }, | |
| error: function(xhr, status){ | |
| callback('Error: [' + xhr.status + '] ' + xhr.statusText, null); | |
| } | |
| }); | |
| }; | |
| var set_list = function(rs) { | |
| $(rs).each(function(i, v) { | |
| $('#tbl_list > tbody').append( | |
| '<tr>' + | |
| '<td>' + v.hospcode + '</td>' + | |
| '<td>' + v.name + '</td>' + | |
| '<td>' + v.hosptype + '</td>' + | |
| '</tr>' | |
| ); | |
| }); | |
| }; | |
| var show_list = function(){ | |
| $('#paging').fadeIn('slow'); | |
| get_total(function(err, total){ | |
| if(err){ | |
| alert(err); | |
| $('#tbl_list > tbody').append( | |
| '<tr><td colspan="3">ไม่พบรายการ</td></tr>' | |
| ); | |
| }else{ | |
| $('#paging').paging(total, { | |
| format: " < . (qq -) nnncnnn (- pp) . >", | |
| perpage: 10, | |
| lapping: 1, | |
| page: 1, | |
| onSelect: function(page){ | |
| get_list(this.slice[0], this.slice[1], function(err, rs){ | |
| $('#tbl_list > tbody').empty(); | |
| if(err){ | |
| alert(err); | |
| $('#tbl_list > tbody').append( | |
| '<tr><td colspan="3">ไม่พบรายการ</td></tr>' | |
| ); | |
| }else{ | |
| set_list(rs); | |
| } | |
| }); | |
| }, | |
| onFormat: paging_format | |
| }); | |
| } | |
| }); | |
| }; | |
| show_list(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment