Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>self</code> variable used in the methods was used in different ways - somewhere it was made a local variable (<code>var self = this</code> within the method) and other places it was used as a variable with a lifetime outside of the method (by omitting <code>var</code>). I don't know if this was intentional to gain some other effect, but making the variable local fixed the problem of paging only happening to the last element.</p> <p>The updated code is at <a href="http://jsbin.com/itajow/11/edit" rel="nofollow">http://jsbin.com/itajow/11/edit</a></p> <p>Note: the declaration <code>addNav:function(self)</code> takes in the <code>self</code> object, but it's called both with and without a parameter in the code, so the first line of the function fixes this by doing <code>self = self || this</code>.</p> <p><em>Edit</em> <br /> To make the list filtering work, the event binding may be rewritten as follows:</p> <pre><code>self.$elem.find(".beautableFilter").on("keyup", function() { var input = $(this).val(); //this == the input element self.addFiltrado(input); }); </code></pre> <p>and the <code>addFilterado</code> method should take <code>input</code> as a parmeter rather than find it itself.</p> <p><em>(the code, to keep it here on SO)</em></p> <pre><code>// JavaScript Document // requiere pubsub!! // requiere contains insensitive!! jQuery.expr[":"].contains=function(a,i,m) { return jQuery(a).text().toUpperCase().indexOf(m[3].toUpperCase())&gt;=0; }; (function(a) { var b=a({});a.subscribe=function() { b.on.apply(b,arguments); },a.unsubscribe=function() { b.off.apply(b,arguments); },a.publish=function() { b.trigger.apply(b,arguments); } })(jQuery); if(typeof Object.create!=='function') { Object.create=function(obj) { function F() { } F.prototype=obj; return new F(); }; } (function($,window,document,undefined) { var Beautable={ init: function(options,elem) { var self=this; self.elem=elem; self.$elem=$(elem); self.$elem.addClass("beautable"); self.ncols=self.$elem.find("th").size(); self.nrows=self.$elem.find("tr").size()-1; if(options===undefined) { options={}; } self.options=$.extend({},$.fn.beautable.options,options); self.subscribeTo(); self.addFooter(); if(self.options.filtro) { self.addHeader(); } self.addData(); if(self.options.multicheck) { self.multicheckFn(); } if(self.options.showTotal) { self.showTotal(); } if(self.options.maxRows&gt;0) { self.addNav(); } self.bindEvents(); //self.hideRows(3,4); }, subscribeTo: function() { //$.subscribe('twitter.getTweets', Twitter.cleanTweets); //$.subscribe('twitter.gotTweets', Twitter.attachTemplate); }, bindEvents: function() { var self=this; if(self.options.multicheck) { self.$checkPadre.on("click",function() { self.multicheckEvent(); }); } if(self.options.maxRows&gt;0&amp;&amp;self.nrows&gt;self.options.maxRows) { self.$elem.find(".beautableButton").on("click",function() { self.buttonClicked($(this)); }); } if(self.options.filtro) { self.$elem.find(".beautableFilter").on("keyup", function() { var input = $(this).val(); //this == the input element self.addFiltrado(input); }); } }, multicheckFn: function() { var self=this; self.$checks=self.$elem.find("input[type='checkbox']"); self.$checkPadre=self.$checks.eq(0); self.$checkPadre.attr("checked",false); }, multicheckEvent: function() { var self=this; self.$checks.attr("checked",self.$checkPadre.is(':checked')); }, showTotal: function() { var self=this; self.$elem.find("tfoot tr td").append('&lt;div class="floatedl"&gt;Total: '+self.nrows+' filas&lt;/div&gt;'); }, addFooter: function() { var self=this; self.$elem.find("tbody").after('&lt;tfoot&gt;&lt;tr&gt;&lt;td colspan="'+self.ncols+'"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;&lt;/tfoot&gt;'); }, addHeader: function() { var self=this; self.$elem.find("thead").prepend('&lt;tr&gt;&lt;th colspan="'+self.ncols+'"&gt;&lt;div class="floatedr"&gt;&lt;input type="text" placeholder="Filtrar..." class="beautableFilter"&gt;&lt;/div&gt;&lt;/th&gt;&lt;/tr&gt;&lt;/tfoot&gt;'); }, addData: function() { var self=this; nrowsdata=0; $.each(self.$elem.find("tbody tr"),function() { $(this).data("nrow",++nrowsdata); }); }, buttonClicked: function($bt) { var self=this; page=$bt.data("page"); maxp=self.options.maxRows*page; minp=maxp-self.options.maxRows+1; self.hideRows(minp,maxp); self.$elem.find(".beautableButton").removeClass("selected"); $bt.addClass("selected"); }, hideRows: function(minR,maxR) { var self=this; $.each(self.$elem.find("tbody tr"),function() { if($(this).data("nrow")&lt;minR||$(this).data("nrow")&gt;maxR) { $(this).hide(); } else { $(this).show(); } }); }, addNav: function(self) { self=self||this; if(self.nrows&gt;self.options.maxRows) { self.npages=Math.ceil(self.nrows/self.options.maxRows); self.$elem.find(".navi").remove(); buttons=""; for(i=1;i&lt;=self.npages;i++) { buttons+="&lt;div class='beautableButton' data-page="+i+"&gt;"+i+"&lt;/div&gt;"; } self.$elem.find("tfoot td").append('&lt;div class="floatedr navi"&gt;'+buttons+'&lt;/div&gt;'); self.buttonClicked($(".beautableButton").eq(0)); } }, addFiltrado: function(input) { var self=this; clearTimeout(self.timer); if(input.length&gt;0) { self.timer=setTimeout(function() { self.filtrar(input); },100); self.$elem.find("tfoot .navi").hide(); } else { self.$elem.find("tfoot .navi").show(); self.filtrar(input); self.addNav(self); } }, filtrar: function(busqueda) { self=this; self.$elem.find("tbody tr").hide(); self.$elem.find('tbody tr td:contains("'+busqueda+'")').filter(function() { $(this).parent().show(); }); } }; $.fn.beautable=function(options) { return this.each(function() { var beautable=Object.create(Beautable); beautable.init(options,this); }); }; $.fn.beautable.options={ multicheck: true, showTotal: false, sumatorio: "", paginated: false, maxRows: 0, filtro: false }; })(jQuery,window,document); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload