File: js/ajaxtable.min.js

Recommend this page to a friend!
  Classes of Joubert RedRat  >  PHP AJAX Table  >  js/ajaxtable.min.js  >  Download  
File: js/ajaxtable.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP AJAX Table
Load HTML tables dynamically using AJAX
Author: By
Last change:
Date: 4 years ago
Size: 11,760 bytes
 

Contents

Download
/*https://github.com/vectornet/ajaxtable*/!function(t){t.fn.extend({ajaxTable:function(s){var e={instance_id:"",cols:[],method:"POST",url:"",params:{},params_new:{},page:1,rows:10,rowsJump:3,rowsJumpResponsive:1,rowsOptions:[5,10,20,50,100,500],sortOrder:"ASC",paramToSort:null,responsive:!1,refreshCallbackFunctionBefore:null,refreshCallbackFunctionAfter:null},i={json_response:{}},a={classTable:"ajaxtable-table",classHead:"ajaxtable-head",classBody:"ajaxtable-body",classFoot:"ajaxtable-foot",classLoading:"ajaxtable-loading",classError:"ajaxtable-error",classNoRows:"ajaxtable-norows",classPaginationHead:"ajaxtable-pagination-head",classPaginationFoot:"ajaxtable-pagination-foot",classPaginationContainer:"ajaxtable-pagination-container",classPaginationTotalRows:"ajaxtable-pagination-totalrows",classPaginationPrevious:"ajaxtable-pagination-previous",classPaginationNext:"ajaxtable-pagination-next",classPaginationFirst:"ajaxtable-pagination-first",classPaginationLast:"ajaxtable-pagination-last",classPaginationReload:"ajaxtable-pagination-reload",classPaginationSetRows:"ajaxtable-pagination-setrows",classPaginationJumps:"ajaxtable-pagination-jumps",classPaginationCurrentPage:"ajaxtable-pagination-currentpage",classCols:"ajaxtable-cols",classColSortable:"ajaxtable-col-sortable",classSortAsc:"ajaxtable-sort-asc",classSortDesc:"ajaxtable-sort-desc",classSortArrow:"ajaxtable-sort-arrow"},o={eventPagePrevious:"ajaxtable-event-pageprevious",eventPageNext:"ajaxtable-event-pagenext",eventPageFirst:"ajaxtable-event-pagefirst",eventPageLast:"ajaxtable-event-pagelast",eventPageJumps:"ajaxtable-event-pagejumps",eventSetRows:"ajaxtable-event-pagesetrows",eventReload:"ajaxtable-event-pagereload"},n={textTotalRows:"Display %rowfirst to %rowlast of %rowtotal rows",textPagination:"Pagination",textPrevious:"Previous",textNext:"Next",textFirst:"First",textLast:"Last",textReload:"Reload",textSetRows:"%row rows per page",textNoRows:"No results found",textError:"An error occurred during retrieving data, try again"};this.each(function(){t(this).data(t.extend(e,i,a,n,s,o)),t(this).data("instance_id",this.id),t(this).buildTableStructure(),t(this).buildTableCols(),t(this).refresh()})},buildTableStructure:function(){t(this).addClass(this.getOption("classTable")),this.append('<thead class="'+this.getOption("classHead")+'"></thead>'),this.append('<tbody class="'+this.getOption("classBody")+'"></tbody>'),this.append('<tfoot class="'+this.getOption("classFoot")+'"></tfoot>'),this.find("thead").append('<tr class="'+this.getOption("classPaginationHead")+'"></tr>'),this.find("tfoot").append('<tr class="'+this.getOption("classPaginationFoot")+'"></tr>')},buildTableCols:function(){var t="",s="",e=0;for(e=0;e<this.getOption("cols").length;e++){t+="<th",this.getOption("cols")[e].headerId&&(t+=' id="'+this.getOption("cols")[e].headerId+'"');var i=[];this.getOption("cols")[e].sortable&&i.push(this.getOption("classColSortable")),this.getOption("cols")[e].headerClass&&i.push(this.getOption("cols")[e].headerClass),i.length>0&&(t+=' class="'+i.join(" ")+'"'),t+=">",this.getOption("cols")[e].headerTitle&&(this.getOption("cols")[e].sortable?(t+='<a href="javascript://" onclick="$(\'#'+this.getOption("instance_id")+"').ajaxTableSort('"+this.getOption("cols")[e].valueToSort+"', this);\">"+this.getOption("cols")[e].headerTitle+"</a>",t+='<span class="'+this.getOption("classSortArrow")+'">',this.getOption("sortCol")&&this.getOption("sortCol")==this.getOption("cols")[e].valueToSort&&(t+="ASC"===this.getOption("sortOrder")?"?":"?"),t+="<span>"):t+=this.getOption("cols")[e].headerTitle),t+="</th>",s+="<colgroup",this.getOption("cols")[e].colgroupClass&&(s+=' class="'+this.getOption("cols")[e].colgroupClass+'"'),this.getOption("cols")[e].colgroupid&&(s+=' id="'+this.getOption("cols")[e].colgroupid+'"'),s+=" ></colgroup>"}this.prepend(s),this.find("thead").append('<tr class="'+this.getOption("classCols")+'">'+t+"</tr>")},refresh:function(){if("function"==typeof this.getOption("refreshCallbackFunctionBefore"))this.getOption("refreshCallbackFunctionBefore")();else if(this.getOption("refreshCallbackFunctionBefore")){var t=this.getOption("refreshCallbackFunctionBefore");window[t]()}if(this.loadAjaxData(),this.bindEventElements(),"function"==typeof this.getOption("refreshCallbackFunctionAfter"))this.getOption("refreshCallbackFunctionAfter")();else if(this.getOption("refreshCallbackFunctionAfter")){var t=this.getOption("refreshCallbackFunctionAfter");window[t]()}},setOption:function(t,s){this.data(t,s)},getOption:function(t){return this.data(t)},setRequestParam:function(t,s){this.data("params_new")[t]=s,this.setOption("page",1)},getRequestParam:function(t){return this.data("params_new")[t]},getDefaultRequestParam:function(t){return this.data("params")[t]},clearRequestParams:function(){this.setOption("params_new",{}),this.setOption("page",1)},getAjaxTableRequestParams:function(){if(this.getOption("responsive")){var t=[],s=0;for(s=0;s<this.getOption("cols").length;s++)t.push(this.getOption("cols")[s].headerTitle);t=JSON.stringify(t)}else var t=this.getOption("cols").length;return{"ajaxTableOptions[responsive]":this.getOption("responsive"),"ajaxTableOptions[cols]":t,"ajaxTableOptions[rows]":this.getOption("rows"),"ajaxTableOptions[page]":this.getOption("page"),"ajaxTableOptions[sortOrder]":this.getOption("sortOrder"),"ajaxTableOptions[sortCol]":null==this.getOption("sortCol")?"":this.getOption("sortCol")}},loadAjaxData:function(){this.removeClass(this.getOption("classError")),this.addClass(this.getOption("classLoading"));var s=t.extend(!1,this.getAjaxTableRequestParams(),this.getOption("params_new"),this.getOption("params"));t.ajax({context:this,url:this.getOption("url"),data:s,type:this.getOption("method"),instance_id:this.getOption("instance_id"),async:!1,dataType:"json",error:function(s,e,i){this.setOption("json_response",{totalPages:1,page:1,totalRecords:0,html:""}),this.clearBody(),this.setOption("page",1),t("."+this.getOption("classPaginationFoot")).html(this.getPagination()),this.find("tbody").html(this.getError()),this.removeClass(this.getOption("classLoading")),this.addClass(this.getOption("classError"))},success:function(s,e,i){this.setOption("json_response",s),this.clearBody(),this.setOption("page",s.page),this.getOption("json_response").totalRecords>10&&this.getOption("rows")>10?t("."+this.getOption("classPaginationHead")).html(this.getPagination()):t("."+this.getOption("classPaginationHead")).html(""),t("."+this.getOption("classPaginationFoot")).html(this.getPagination()),this.getOption("json_response").totalRecords>0?this.find("tbody").html(this.getOption("json_response").html):this.find("tbody").html(this.getNoRows()),this.removeClass(this.getOption("classLoading"))}})},getNoRows:function(){return'<tr class="'+this.getOption("classNoRows")+'"><td colspan="'+this.getOption("cols").length+'">'+this.getOption("textNoRows")+"</td></tr>"},getError:function(){return'<tr class="'+this.getOption("classError")+'"><td colspan="'+this.getOption("cols").length+'">'+this.getOption("textError")+"</td></tr>"},jumpToPage:function(s){s<=this.getOption("json_response").totalPages&&(this.setOption("page",s),t(this).refresh())},ajaxTableSort:function(s,e){this.getOption("sortCol")===s?this.setOption("sortOrder","DESC"===this.getOption("sortOrder")?"ASC":"DESC"):this.setOption("sortOrder","ASC"),this.setOption("sortCol",s),t("."+this.getOption("classSortArrow")).html(""),t("."+this.getOption("classSortAsc")).removeClass(this.getOption("classSortAsc")),t("."+this.getOption("classSortDesc")).removeClass(this.getOption("classSortDesc")),t(e).parent().addClass(this.getOption("ASC"===this.getOption("sortOrder")?"classSortAsc":"classSortDesc")).find("span").html("ASC"===this.getOption("sortOrder")?"?":"?"),t(this).refresh()},clearBody:function(){this.find("tbody").length&&this.find("tbody").html("")},getPagination:function(){var t='<td colspan="'+this.getOption("cols").length+'">';if(t+='<div class="'+this.getOption("classPaginationContainer")+'"><ul>',this.getOption("page")>1){var s="<li "+(this.getOption("classPaginationFirst")?'class="'+this.getOption("classPaginationFirst")+'"':"")+">";s+='<a href="javascript://" onclick="$(\'#'+this.attr("id")+"').goToFirst();\">"+this.getOption("textFirst")+"</a>",s+="</li>";var e="<li "+(this.getOption("classPaginationPrevious")?'class="'+this.getOption("classPaginationPrevious")+'"':"")+">";e+='<a href="javascript://" onclick="$(\'#'+this.attr("id")+"').goToPrevious();\">"+this.getOption("textPrevious")+"</a>",e+="</li>",t+=s+e}for(var i="",a=this.getOption("responsive")&&screen.width<=480?this.getOption("rowsJumpResponsive"):this.getOption("rowsJump"),o=-a;a>=o;o++)parseInt(this.getOption("page"))+o<=this.getOption("json_response").totalPages&&parseInt(this.getOption("page"))+o>0&&(i+=0==o?"<li"+(this.getOption("classPaginationCurrentPage")?' class="'+this.getOption("classPaginationCurrentPage")+'"':"")+"><a>"+parseInt(this.getOption("page"))+"</a></li>":"<li"+(this.getOption("classPaginationJumps")?' class="'+this.getOption("classPaginationJumps")+'"':"")+'><a href="javascript://" onclick="$(\'#'+this.attr("id")+"').jumpToPage("+(parseInt(this.getOption("page"))+o)+');">'+(parseInt(this.getOption("page"))+o)+"</a></li>");if(t+=i,this.getOption("page")<this.getOption("json_response").totalPages){var n="<li "+(this.getOption("classPaginationNext")?'class="'+this.getOption("classPaginationNext")+'"':"")+">";n+='<a href="javascript://" onclick="$(\'#'+this.attr("id")+"').goToNext();\">"+this.getOption("textNext")+"</a>",n+="</li>";var r="<li "+(this.getOption("classPaginationLast")?'class="'+this.getOption("classPaginationLast")+'"':"")+">";r+='<a href="javascript://" onclick="$(\'#'+this.attr("id")+"').goToLast();\">"+this.getOption("textLast")+"</a>",r+="</li>",t+=n+r}var l="<li "+(this.getOption("classPaginationReload")?'class="'+this.getOption("classPaginationReload")+'"':"")+">";l+='<a href="javascript://" onclick="$(\'#'+this.attr("id")+"').refresh();\">"+this.getOption("textReload")+"</a>",l+="</li>",t+=l,t+="</ul></div>",t+='<div class="'+this.getOption("classPaginationSetRows")+'">',t+="<select onchange=\"$('#"+this.attr("id")+"').changeRowsPerPage(this.value);\">";for(var o=0;o<this.getOption("rowsOptions").length;o++)t+='<option value="'+this.getOption("rowsOptions")[o]+'"',t+=this.getOption("rows")==this.getOption("rowsOptions")[o]?' selected="selected"':"",t+=">",t+=this.getOption("textSetRows").replace("%row",this.getOption("rowsOptions")[o])+"</option>";if(t+="</select></div>",this.getOption("json_response").totalRecords>0){var p=this.getOption("textTotalRows");p=p.replace("%rowfirst",this.getOption("rows")*this.getOption("page")+1-this.getOption("rows")),p=this.getOption("page")*this.getOption("rows")>this.getOption("json_response").totalRecords?p.replace("%rowlast",this.getOption("json_response").totalRecords):p.replace("%rowlast",this.getOption("page")*this.getOption("rows")),p=p.replace("%rowtotal",this.getOption("json_response").totalRecords)}else var p=this.getOption("textNoRows");return t+='<div class="'+this.getOption("classPaginationTotalRows")+'">'+p+"</div>",t+="</td>"},changeRowsPerPage:function(t){this.setOption("rows",t),this.refresh()},goToPrevious:function(){this.setOption("page",this.getOption("page")>1?this.getOption("page")-1:1),this.refresh()},goToNext:function(){this.setOption("page",this.getOption("page")<this.getOption("json_response").totalPages?this.getOption("page")+1:this.getOption("json_response").totalPages),this.refresh()},goToFirst:function(){this.setOption("page",1),this.refresh()},goToLast:function(){this.setOption("page",this.getOption("json_response").totalPages),this.refresh()},bindEventElements:function(){}})}(jQuery);

For more information send a message to info at phpclasses dot org.