|
@@ -0,0 +1,659 @@
|
|
|
+
|
|
|
+!function($){
|
|
|
+ var tipmsg="没有找到相关内容";
|
|
|
+ var _nilHtml='<div class="text-center" style="margin:-80px auto;"><img src="/images/findnull.png" class="b-findnull"><h4><span class="glyphicon glyphicon-question-sign text-primary"></span > <strong class="text-muted">$tipmsg</strong></h4></div>';
|
|
|
+ var DataTable = function ( element, options ) {
|
|
|
+ this.$element = $(element);
|
|
|
+ this.options = options;
|
|
|
+ tipmsg=this.options.tipmsg||tipmsg
|
|
|
+ this.options.nilHtml=this.options.nilHtml||_nilHtml.replace("$tipmsg",tipmsg)
|
|
|
+ this.enabled = true;
|
|
|
+ this.columns = [];
|
|
|
+ this.rows = [];
|
|
|
+ // this needs to be handled better
|
|
|
+ //this.localStorageId = "datatable_" + (options.id || options.url.replace(/\W/ig, '_'));
|
|
|
+ this.$default = this.$element.children().length ?this.$element.children():$("<div/>")
|
|
|
+ .addClass("alert alert-error").html(this.options.nilHtml);
|
|
|
+ this.$element.addClass("clearfix");
|
|
|
+ // clear out the localStorage for this entry
|
|
|
+ // if(localStorage) {
|
|
|
+ // localStorage[this.localStorageId] = 'false';
|
|
|
+ // }
|
|
|
+ //在渲染之前事件
|
|
|
+ if(this.options.tablePreRender && typeof this.options.tablePreRender === 'function')
|
|
|
+ this.options.tablePreRender.call(this)
|
|
|
+ // initialize the toolbar
|
|
|
+ this.render();
|
|
|
+ this.toolbar();
|
|
|
+ };
|
|
|
+DataTable.prototype = {
|
|
|
+ render: function () {
|
|
|
+ var o = this.options, $e = this.$element;
|
|
|
+ // show loading
|
|
|
+ this.loading( true );
|
|
|
+ // reset the columns and rows
|
|
|
+ this.columns = [];
|
|
|
+ this.rows = [];
|
|
|
+ this.buttons = [];
|
|
|
+ this.$wrapper = undefined;
|
|
|
+ this.$table = undefined;
|
|
|
+ this.$header = undefined;
|
|
|
+ this.$body = undefined;
|
|
|
+ this.$pagination = undefined;
|
|
|
+ this.$pages = $("<div/>").css("background-color",this.options.pagebg);
|
|
|
+ //if(this.$toolbar) this.$toolbar.remove();
|
|
|
+
|
|
|
+ // localize the object
|
|
|
+ var that = this;
|
|
|
+
|
|
|
+ // pull in the data from the ajax call
|
|
|
+ if(o.url !== "") {
|
|
|
+ $.ajax({
|
|
|
+ url: o.url
|
|
|
+ , type: "POST"
|
|
|
+ , dataType: "json"
|
|
|
+ , async: o.isAsync
|
|
|
+ , data: $.extend({}, o.post, {
|
|
|
+ currentPage: o.currentPage
|
|
|
+ , perPage: o.perPage
|
|
|
+ })
|
|
|
+ , success: function( res ) {
|
|
|
+ if(o.ajaxSuccess && typeof o.ajaxSuccess === 'function')
|
|
|
+ o.ajaxSuccess.call(that,res,o);
|
|
|
+ if(o.continueBody){
|
|
|
+ //var res={totalRows:20,data:[{"s_name":"张三","l_registedate":"555"},{"s_name":"gggggg","l_registedate":"555"},{"s_name":"ttttt","l_registedate":"555"}]}
|
|
|
+ that.resultset = res;
|
|
|
+ if(!res || res === undefined || !res.data || res.data.length == 0) {
|
|
|
+ $("#audit").append(that.table());
|
|
|
+ that.header();
|
|
|
+ showError.call(that);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // clear out the current elements in the container
|
|
|
+ $e.empty();
|
|
|
+ // set the sort and filter configuration
|
|
|
+ o.totalRows = res.totalRows;
|
|
|
+ // set the current page if we're forcing it from the server
|
|
|
+ if(res.currentPage) o.currentPage = parseInt(res.currentPage);
|
|
|
+
|
|
|
+ // append the table
|
|
|
+ $e.append(that.table());
|
|
|
+ //显示分页
|
|
|
+ if(o.showPagination){
|
|
|
+ $e.append(that.$pages.append(that.pagination()))
|
|
|
+ }
|
|
|
+ // render the rest of the table
|
|
|
+ if(o.showHeader) that.header();
|
|
|
+
|
|
|
+ // fill in the table body
|
|
|
+ that.body();
|
|
|
+ // render the pagination
|
|
|
+ //if(o.showPagination && that.pagination())
|
|
|
+
|
|
|
+ // initialize the toolbar
|
|
|
+
|
|
|
+ // nearly complete... let the user apply any final adjustments
|
|
|
+ if(o.tableCallback && typeof o.tableCallback === 'function')
|
|
|
+ o.tableCallback.call(that);
|
|
|
+ }
|
|
|
+ that.loading( false );
|
|
|
+ }
|
|
|
+ , error: function( e ) {
|
|
|
+ if(o.ajaxError && typeof o.ajaxError === 'function')
|
|
|
+ o.ajaxError.call(that);
|
|
|
+ showError.call(that);
|
|
|
+ that.loading( false );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ , loading: function ( show) {
|
|
|
+ if(this.options.showLoading){
|
|
|
+ var $e = this.$element;
|
|
|
+ var loadp
|
|
|
+ if(!this.$loading) {
|
|
|
+ loadp=$("<div/>").addClass("progress-bar");
|
|
|
+ this.$loading = $("<div/>")
|
|
|
+ .css({
|
|
|
+ position: 'absolute'
|
|
|
+ , top: parseInt($e.position().top) + 5
|
|
|
+ , left: parseInt($e.position().left) + parseInt($e.css("marginLeft")) + Math.floor($e.width() / 4)
|
|
|
+ , width: Math.floor($e.width() / 2) + "px"
|
|
|
+ })
|
|
|
+ .append(
|
|
|
+ $("<div/>")
|
|
|
+ .addClass("progress progress-striped active")
|
|
|
+ .append(
|
|
|
+ loadp
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .appendTo(document.body)
|
|
|
+ }
|
|
|
+ if(show) {
|
|
|
+ $e.css({ opacity: 0.2 });
|
|
|
+ window._n=100;
|
|
|
+ var n=1;
|
|
|
+ this.LL=setInterval(function(){
|
|
|
+ n++
|
|
|
+ if(n<4){
|
|
|
+ $(".progress-bar").css("width",window._n+"%")
|
|
|
+ }
|
|
|
+ },100)
|
|
|
+
|
|
|
+ }else {
|
|
|
+ $e.css({ opacity: 1 });
|
|
|
+ this.$loading.remove();
|
|
|
+ this.$loading = undefined;
|
|
|
+ clearInterval(this.LL)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ , toolbar: function () {
|
|
|
+ if(this.$toolbar) return ;
|
|
|
+ this.buttons=[]
|
|
|
+ if(!this.options.buttons||!this.options.buttons.length) return;
|
|
|
+ var o = this.options
|
|
|
+ , $e = this.$element
|
|
|
+ , that = this;
|
|
|
+
|
|
|
+
|
|
|
+ this.$toolbar = $("<div/>").addClass("btn-group-fat");
|
|
|
+ if(o.toolbarCss){
|
|
|
+ this.$toolbar.css(o.toolbarCss)
|
|
|
+ }
|
|
|
+ this.$button_group = $("<div/>").addClass("btn-group").appendTo(this.$toolbar);
|
|
|
+
|
|
|
+ // add all the custom buttons
|
|
|
+
|
|
|
+ for(var i = 0; i < o.buttons.length; i++) {
|
|
|
+ that.buttons.push(o.buttons[i]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // attach all buttons to the toolbar
|
|
|
+ $.each(this.buttons, function() {
|
|
|
+ that.$button_group.append(this);
|
|
|
+ });
|
|
|
+
|
|
|
+ // attach the toolbar to the section header
|
|
|
+ $e.before(this.$toolbar);
|
|
|
+ return this.$toolbar;
|
|
|
+ }
|
|
|
+
|
|
|
+ , table: function () {
|
|
|
+ var $e = this.$element
|
|
|
+ , o = this.options;
|
|
|
+ if(!this.$table_wrapper) {
|
|
|
+ this.$wrapper = $("<div/>")
|
|
|
+ .addClass("dt-table-wrapper").css(o.css);
|
|
|
+ }
|
|
|
+ if (!this.$table) {
|
|
|
+ this.$table = $('<table/>')
|
|
|
+ .addClass(o.tableClass).addClass(o.classname);
|
|
|
+ }
|
|
|
+ this.$wrapper.append(this.$table);
|
|
|
+ return this.$wrapper;
|
|
|
+ },
|
|
|
+ checkAll:function(checked){
|
|
|
+ this.$body.find("input[name=_tableCheck]").prop('checked',(checked?true:false));
|
|
|
+ this.$body.find("tr").css("background-color",checked?"#EEF3F9":"")
|
|
|
+ },
|
|
|
+ getSelect:function(){
|
|
|
+ var val=this.$body.find("input[name=_tableCheck]:checked"),res=[];
|
|
|
+ if(val&&val.length>0){
|
|
|
+ val.each(function(i,ad){
|
|
|
+ res.push($(this).val());
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+ , selectAll:function(){
|
|
|
+ var c=this.options.checkbox;
|
|
|
+ that=this;
|
|
|
+ if(c&&c=="check"){
|
|
|
+ this.$header.off('click', '[name="btSelectAll"]')
|
|
|
+ .on('click', '[name="btSelectAll"]', function () {
|
|
|
+ var checked = $(this).prop('checked');
|
|
|
+ that.checkAll(checked);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ , header: function () {
|
|
|
+ var o = this.options
|
|
|
+ , res = this.resultset;
|
|
|
+ if(!this.$header) {
|
|
|
+ this.$header = $('<thead/>');
|
|
|
+ var row = $('<tr/>').css("background","#f2f2f2").css("background-image",
|
|
|
+ "-webkit-gradient(linear,left 0,left 100%,from(#f8f8f8),to(#ececec))");
|
|
|
+
|
|
|
+ // loop through the columns
|
|
|
+ if(o.checkbox){
|
|
|
+ if(o.checkbox=="check"&&o.checkboxHeader){
|
|
|
+ row.append($('<th><input name="btSelectAll" type="checkbox" /><small>全选</small></th>'))
|
|
|
+ this.selectAll();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for(var column in o.columns) {
|
|
|
+ var $cell = this.column(column)
|
|
|
+ , colprop = $cell.data("column_properties");
|
|
|
+
|
|
|
+ // attach the sort click event
|
|
|
+ row.append($cell);
|
|
|
+ this.$header.append(row);
|
|
|
+ this.columns.push($cell);
|
|
|
+ }
|
|
|
+
|
|
|
+ // any final user adjustments to the header
|
|
|
+ if(o.headerCallback && typeof o.headerCallback === 'function')
|
|
|
+ o.headerCallback.call(this);
|
|
|
+ this.$table.append(this.$header);
|
|
|
+ }
|
|
|
+ return this.$header;
|
|
|
+ }
|
|
|
+ , body: function () {
|
|
|
+ var res = this.resultset
|
|
|
+ , o = this.options;
|
|
|
+ if(!this.$body) {
|
|
|
+ this.$body = $('<tbody></tbody>');
|
|
|
+
|
|
|
+ // loop through the results
|
|
|
+ for(var i = 0; i < res.data.length; i++) {
|
|
|
+ var row = this.row(res.data[i]);
|
|
|
+ this.$body.append(row);
|
|
|
+ this.rows.push(row);
|
|
|
+ }
|
|
|
+ this.selectone();
|
|
|
+ if(o.showFilterRow) this.$body.prepend(this.filter());
|
|
|
+ this.$table.append(this.$body);
|
|
|
+ }
|
|
|
+ return this.$body;
|
|
|
+ },
|
|
|
+ selectone:function(){
|
|
|
+ that=this;
|
|
|
+ if(that.$header){
|
|
|
+ var cb=that.$body.find('input[name="_tableCheck"]');
|
|
|
+ this.$body.off('click','input[name="_tableCheck"]').on("click",'input[name="_tableCheck"]',function(){
|
|
|
+ $(this).closest("tr").css("background-color",$(this).prop("checked")?"#EEF3F9":"")
|
|
|
+ var cb2=that.$body.find('input[name="_tableCheck"]:checked');
|
|
|
+ that.$header.find('[name="btSelectAll"]').prop("checked",cb.length==cb2.length)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ , row: function ( rowdata ) {
|
|
|
+ var $row = $("<tr/>")
|
|
|
+ , o = this.options;
|
|
|
+ if(o.columns&&o.columns.length){
|
|
|
+ if(o.checkbox){
|
|
|
+ if(o.checkbox=="check"&&o.idField){
|
|
|
+ $row.append($('<td><input value="'+rowdata[o.idField]+'" name="_tableCheck" type="checkbox" /></td>'))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // loop through the columns
|
|
|
+ for(var column in o.columns) {
|
|
|
+ var cell = this.cell( rowdata, column );
|
|
|
+ $row.append(cell);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // callback for postprocessing on the row
|
|
|
+ if(o.rowCallback && typeof o.rowCallback === "function")
|
|
|
+ $row = o.rowCallback( $row, rowdata );
|
|
|
+ return $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ , cell: function ( data, column ) {
|
|
|
+
|
|
|
+ var celldata = data[this.options.columns[column].field] || this.options.columns[column].custom
|
|
|
+ , $cell = $('<td/>')
|
|
|
+ , o = this.options;
|
|
|
+ // preprocess on the cell data for a column
|
|
|
+ if(o.columns[column].callback && typeof o.columns[column].callback === "function")
|
|
|
+ celldata = o.columns[column].callback.call( $cell, data,celldata,o.columns[column],column )
|
|
|
+
|
|
|
+ $cell.data("cell_properties", o.columns[column])
|
|
|
+ .addClass(o.columns[column].classname)
|
|
|
+ .append(celldata || " ")
|
|
|
+
|
|
|
+ if(o.columns[column].css) $cell.css(o.columns[column].css);
|
|
|
+ if(o.columns[column].hidden) $cell.hide();
|
|
|
+ return $cell;
|
|
|
+ }
|
|
|
+
|
|
|
+ , column: function ( column ) {
|
|
|
+ var $cell = $('<th></th>')
|
|
|
+ , o = this.options
|
|
|
+ , classname = "dt-column_" + column + Math.floor((Math.random()*1000)+1);
|
|
|
+ var tempClass=o.columns[column].classname;
|
|
|
+ o.columns[column].classname = (tempClass?(tempClass+" "):"")+classname;
|
|
|
+
|
|
|
+ $cell
|
|
|
+ .data("column_properties", o.columns[column])
|
|
|
+ .addClass(classname)
|
|
|
+ .text(o.columns[column].title);
|
|
|
+ if(o.columns[column].css) $cell.css(o.columns[column].css);
|
|
|
+ if(o.columns[column].hidden) $cell.hide();
|
|
|
+ return $cell;
|
|
|
+ }
|
|
|
+ , pagination: function () {
|
|
|
+ //获取当前地址url 如果是订阅消息页面 执行方法 removeChecked()
|
|
|
+ //该方法再orderlist.html页面 用于翻页取消全选状态
|
|
|
+ var orderMessage_list = window.location.pathname;
|
|
|
+ if(orderMessage_list=="/manage/orderMessage/list"){
|
|
|
+ removeChecked();
|
|
|
+ }
|
|
|
+ var $e = this.$element
|
|
|
+ , that = this
|
|
|
+ , o = this.options
|
|
|
+ , res = this.resultset;
|
|
|
+ // no paging needed
|
|
|
+ //if(o.perPage >= res.totalRows) return;
|
|
|
+ if(!this.$pagination) {
|
|
|
+ this.$pagination = $("<div/>").addClass("text-center").css("margin-top","-20px");
|
|
|
+ if(o.pageclass) this.$pagination.addClass(o.pageclass)
|
|
|
+ // how many pages?
|
|
|
+ o.pageCount = Math.ceil(res.totalRows / o.perPage);
|
|
|
+
|
|
|
+ // setup the pager container and the quick page buttons
|
|
|
+ var $pager = $("<ul></ul>").addClass("pagination")
|
|
|
+ , $first = $("<li></li>").append(
|
|
|
+ $("<a></a>")
|
|
|
+ .attr("href", "#")
|
|
|
+ .data("page", 1)
|
|
|
+ .html("«")
|
|
|
+ .click(function() {
|
|
|
+ if ($(this).closest("li").attr("class")=="disabled"){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ o.currentPage = 1
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ )
|
|
|
+ , $previous = $("<li></li>").append(
|
|
|
+ $("<a></a>")
|
|
|
+ .attr("href", "#")
|
|
|
+ .data("page", o.currentPage - 1)
|
|
|
+ .html("<")
|
|
|
+ .click(function() {
|
|
|
+ if ($(this).closest("li").attr("class")=="disabled"){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ o.currentPage -= 1
|
|
|
+ o.currentPage = o.currentPage >= 1 ? o.currentPage : 1
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ )
|
|
|
+ , $next = $("<li></li>").append(
|
|
|
+ $("<a></a>")
|
|
|
+ .attr("href", "#")
|
|
|
+ .data("page", o.currentPage + 1)
|
|
|
+ .html(">")
|
|
|
+ .click(function() {
|
|
|
+ if ($(this).closest("li").attr("class")=="disabled"){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ o.currentPage += 1
|
|
|
+ o.currentPage = o.currentPage <= o.pageCount? o.currentPage : o.pageCount
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ )
|
|
|
+ , $last = $("<li></li>").append(
|
|
|
+ $("<a></a>")
|
|
|
+ .attr("href", "#")
|
|
|
+ .data("page", o.pageCount)
|
|
|
+ .html("»")
|
|
|
+ .click(function() {
|
|
|
+ if ($(this).closest("li").attr("class")=="disabled"){
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ o.currentPage = o.pageCount
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ var totalPages = o.pagePadding * 2
|
|
|
+ , start
|
|
|
+ , end;
|
|
|
+ if(totalPages >= o.pageCount) {
|
|
|
+ start = 1;
|
|
|
+ end = o.pageCount;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ start = o.currentPage - o.pagePadding;
|
|
|
+ if(start <= 0) start = 1;
|
|
|
+
|
|
|
+ end = start + totalPages;
|
|
|
+ if(end > o.pageCount) {
|
|
|
+ end = o.pageCount;
|
|
|
+ start = end - totalPages;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // append the pagination links
|
|
|
+ for(var i = start; i <= end; i++) {
|
|
|
+ var $link = $("<li></li>")
|
|
|
+ .append(
|
|
|
+ $("<a></a>")
|
|
|
+ .attr("href", "#")
|
|
|
+ .data("page", i)
|
|
|
+ .text(i)
|
|
|
+ .click(function() {
|
|
|
+ o.currentPage = $(this).data('page')
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ if(i == o.currentPage) $link.addClass("active");
|
|
|
+ $pager.append($link);
|
|
|
+ }
|
|
|
+
|
|
|
+ // append quick jump buttons
|
|
|
+ if(o.currentPage == 1) {
|
|
|
+ $first.addClass("disabled");
|
|
|
+ $previous.addClass("disabled");
|
|
|
+ }
|
|
|
+ if(o.currentPage == o.pageCount) {
|
|
|
+ $next.addClass("disabled");
|
|
|
+ $last.addClass("disabled");
|
|
|
+ }
|
|
|
+ $pager.prepend($first, $previous);
|
|
|
+ $pager.append($next, $last);
|
|
|
+
|
|
|
+ this.$pagination.append($pager);
|
|
|
+ }
|
|
|
+ return this.$pagination;
|
|
|
+ }
|
|
|
+ , remove: function() {
|
|
|
+ var $e = this.$element
|
|
|
+ if(this.$section_header) this.$section_header.remove();
|
|
|
+ $e.data("datatable", null);
|
|
|
+ $e.empty();
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ function _updatePerPage(that) {
|
|
|
+ var o = that.options;
|
|
|
+ // update the perpage value
|
|
|
+ o.perPage = $(this).data("value");
|
|
|
+ // the offset
|
|
|
+ var offset = o.currentPage * o.perPage;
|
|
|
+ while(offset > o.totalRows) {
|
|
|
+ o.currentPage--;
|
|
|
+ offset = o.currentPage * o.perPage;
|
|
|
+ }
|
|
|
+ if(o.currentPage < 1) o.currentPage = 1;
|
|
|
+ if($(this).popover) $(this).popover('hide');
|
|
|
+ // update the table
|
|
|
+ that.render();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ function _initPerPage() {
|
|
|
+ var o = this.options
|
|
|
+ , $e = this.$element
|
|
|
+ , that = this;
|
|
|
+
|
|
|
+ // per page options and current filter/sorting
|
|
|
+ var $perpage_select = $("<a></a>")
|
|
|
+ .addClass("btn dropdown-toggle")
|
|
|
+ .data("content", "Change the number of rows per page.")
|
|
|
+ .attr("data-toggle", "dropdown")
|
|
|
+ .html(o.perPage + " ")
|
|
|
+ .css({ fontWeight: 'normal' })
|
|
|
+ .append(
|
|
|
+ $("<span></span>")
|
|
|
+ .addClass("caret")
|
|
|
+ )
|
|
|
+ .popover({
|
|
|
+ "trigger": 'hover',
|
|
|
+ "placement":'top'
|
|
|
+ });
|
|
|
+ this.buttons.push($perpage_select);
|
|
|
+
|
|
|
+ var $perpage_values = $("<ul></ul>")
|
|
|
+ .addClass("dropdown-menu")
|
|
|
+ .css({ fontSize: 'initial', fontWeight: 'normal' })
|
|
|
+ .append(
|
|
|
+ $('<li data-value="10"><a href="#">10</a></li>')
|
|
|
+ .click(function() { _updatePerPage.call(this, that); return false; })
|
|
|
+ , $('<li data-value="20"><a href="#">20</a></li>')
|
|
|
+ .click(function() { _updatePerPage.call(this, that); return false; })
|
|
|
+ , $('<li data-value="50"><a href="#">50</a></li>')
|
|
|
+ .click(function() { _updatePerPage.call(this, that); return false; })
|
|
|
+ , $('<li data-value="100"><a href="#">100</a></li>')
|
|
|
+ .click(function() { _updatePerPage.call(this, that); return false; })
|
|
|
+ , $('<li data-value="150"><a href="#">200</a></li>')
|
|
|
+ .click(function() { _updatePerPage.call(this, that); return false; })
|
|
|
+ );
|
|
|
+ this.buttons.push($perpage_values);
|
|
|
+ }
|
|
|
+
|
|
|
+ function _initTableInfo() {
|
|
|
+ var o = this.options
|
|
|
+ , $e = this.$element
|
|
|
+ , $info = $("<a></a>");
|
|
|
+
|
|
|
+ // render the display modal button
|
|
|
+ $info
|
|
|
+ .addClass("btn")
|
|
|
+ .attr("href", "#")
|
|
|
+ .append(
|
|
|
+ $("<span></span>")
|
|
|
+ .addClass("glyphicon glyphicon-info-sign")
|
|
|
+ )
|
|
|
+ .click(function() {
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+ var $page_sort = []
|
|
|
+ , $page_filter = [];
|
|
|
+
|
|
|
+ // sort
|
|
|
+ $.each(o.sort, function(i, v){
|
|
|
+ if(!v.length) return;
|
|
|
+ var heading;
|
|
|
+ for(var column in o.columns) {
|
|
|
+ if(o.columns[column].field == v[0]) heading = o.columns[column].title;
|
|
|
+ }
|
|
|
+ $page_sort.push( heading + " " + v[1].toUpperCase() );
|
|
|
+ });
|
|
|
+
|
|
|
+ // filter
|
|
|
+ $.each(o.filter, function(k, v) {
|
|
|
+ var heading;
|
|
|
+ for(var column in o.columns) {
|
|
|
+ if(o.columns[column].field == k) heading = o.columns[column].title;
|
|
|
+ }
|
|
|
+ $page_filter.push( (heading || k) + " = '" + v + "'" );
|
|
|
+ });
|
|
|
+ $($info)
|
|
|
+ .data("content",
|
|
|
+ $('<dl></dl>').append(
|
|
|
+ $page_sort.length > 0 ? '<dt><i class="icon-th-list"></i> Sort:</dt><dd>' + $page_sort.join(", ") + '</dd>' : ''
|
|
|
+ ,
|
|
|
+ $page_filter.length > 0 ? '<dt><i class="icon-filter"></i> Filter:</dt><dd>' + $page_filter.join(", ") + '</dd>' : ''
|
|
|
+ ))
|
|
|
+ .popover({
|
|
|
+ placement: "bottom"
|
|
|
+ });
|
|
|
+
|
|
|
+ this.buttons.unshift($info);
|
|
|
+ }
|
|
|
+ function showError() {
|
|
|
+ var o = this.options
|
|
|
+ , $e = this.$element;
|
|
|
+ // $e.empty();
|
|
|
+ // initialize the toolbar
|
|
|
+ this.toolbar();
|
|
|
+ // nearly complete... let the user apply any final adjustments
|
|
|
+ if(o.tableCallback && typeof o.tableCallback === 'function')
|
|
|
+ o.tableCallback.call(this);
|
|
|
+ this.loading( false );
|
|
|
+ if(this.$default) $e.append(this.$default);
|
|
|
+ }
|
|
|
+
|
|
|
+ $.fn.datatable = function ( options,_relatedTarget,flag ) {
|
|
|
+ var value;
|
|
|
+ var data = this.data("datatable");
|
|
|
+ if (typeof options === 'string') {
|
|
|
+ if (!data) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ value = data[options]&&data[options](_relatedTarget);
|
|
|
+ if (options === 'destroy') {
|
|
|
+ this.removeData('bootstrap.table');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!data||flag) {
|
|
|
+ $.fn.datatable.init.call(this,options,"datatable",flag)
|
|
|
+ }
|
|
|
+ return typeof value === 'undefined' ? this : value;
|
|
|
+ };
|
|
|
+ $.fn.datatable.init = function (options,name,flag) {
|
|
|
+ options = $.extend({}, $.fn.datatable.defaults, options);
|
|
|
+ var datatable = $(this).data(name);
|
|
|
+ if (!datatable||flag) {
|
|
|
+ datatable = new DataTable(this, options);
|
|
|
+ $(this).data(name, datatable);
|
|
|
+ }
|
|
|
+ return datatable;
|
|
|
+ };
|
|
|
+
|
|
|
+ $.fn.datatable.defaults = {
|
|
|
+ debug: true,
|
|
|
+ id: undefined,
|
|
|
+ tableClass: 'table',
|
|
|
+ css:{},
|
|
|
+ perPage: 10,
|
|
|
+ pagePadding: 2,
|
|
|
+ post: {},
|
|
|
+ buttons: [],
|
|
|
+ pageclass:'',
|
|
|
+ classname:'table-hover',
|
|
|
+ showHeader:true
|
|
|
+ ,checkbox:"" //check radio
|
|
|
+ ,idField:""
|
|
|
+ ,checkboxHeader:true,
|
|
|
+ sectionHeader: undefined,
|
|
|
+ totalRows: 0,
|
|
|
+ currentPage: 1,
|
|
|
+ showPagination: true,
|
|
|
+ showTopPagination: false,
|
|
|
+ allowExport: false,
|
|
|
+ allowOverflow: true,
|
|
|
+ url: '',
|
|
|
+ columns: [],
|
|
|
+ rowCallback: undefined,
|
|
|
+ tableCallback: undefined,
|
|
|
+ headerCallback: undefined,
|
|
|
+ tablePreRender: undefined,
|
|
|
+ ajaxSuccess:undefined,
|
|
|
+ continueBody:true,//继续解析主体
|
|
|
+ ajaxError:undefined,
|
|
|
+ pagebg:"",//分页条背景色
|
|
|
+ showLoading:false, //显示进度条
|
|
|
+ isAsync: false
|
|
|
+ //,toolbarCss:{"background-color":""} //工具条颜色
|
|
|
+ };
|
|
|
+}(jQuery)
|