1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
var lazyload_app = function(){ function init(){ $('#mousewheel_example').scroll(function() { var $this = $(this); var $table = $this.find('table'); var cw = $this.width(); var tw = $table.width(); var left = $this.scrollLeft(); //console.log($this.width()); //console.log($table.width()); //console.log($this.scrollLeft()); if(cw+left == tw){ //console.log('Right!'); var index = get_column_index(); get_column_data(index); } }); } function fetch(column_index){ get_column_data(column_index); } function get_column_index(){ var $table = $('#itable'); //-2: 減掉input column, 然後再減掉1才是index var column_index = $table.find('tr:first td').length - 2; //Return next index return column_index + 1; } function get_column_data(column_index){ var params = { from: $('#from_date').val(), to: $('#end_date').val(), vital_type: $('#vital_type').val(), patient_id: $('#patient_id').val(), column_index:column_index } $.ajax({ type: 'get', url: base_url + 'inquire/ajax_column_data', data: params, dataType: 'json', success: function(res){ if(typeof res.status == 'undefined'){ alert(res); }else if(res.status == 'fail'){ alert(res.message); }else{ console.log(res); show_columns(res.data); syncscroll_app.refresh(); } }, error: function(res){ //var errors = res.responseJSON; //show_response_error(errors); if(typeof res.responseText != 'undefined'){ alert(res.responseText); }else{ alert(res); } } }); } function show_columns(data){ var $table = $('#itable'); for(var i = 0; i < data.length; i++){ var col_data = data[i]; $table.find('tr').each(function(index){ var $this = $(this); $this.append($(col_data[index])); }); } } return { init: init, fetch: fetch } }(); |