Able by Ajax front-end Parameters

Source: Internet
Author: User

Able by Ajax front-end Parameters

Datatable implements ajax dynamic paging and designs the dom format of each column cell.

 

Id: Table id
Ordering: whether it can be sorted
Paging: whether to display data on pages after all the table data has been loaded
Processing: whether to asynchronously load table data not displayed
AoColumnDefs: column control. aTargets indicates the selected control column, and mRender indicates the operation on the selected column.
BProcessing: whether to display the progress bar when loading data
ServerSide: whether to load data from the server
TableTools: datatable extension tool library. This function uses the excel export button (buttons are only used as event triggers, fnclick defines events, and sends requests to the background. The excel export function has been rewritten at the backend)
FnDrawCallback: Page change callback function
Ajax: url indicates the source address of table data. ajax requests are sent for each sorting, page turning, and search. error indicates a callback function for request failure.
The above are dataTable built-in API, query details can visit the site: http://datatables.net /.
The following is the original tableablebyajax parameter tableObj:
ColumnsSetting:
Length: Number of columns in the table,
ShowColumns: The data to be displayed corresponds to the key value in the array data. The default value is all the key values in data,
Edit_columns: edit each column. The first parameter of each array indicates the array of the nth column (starting from 0 ), the second parameter defines the format of each cell in the column (for example, convert the original data into hyperlinks and add attributes)
FnDrawCallback: Used in the built-in fnDrawCallback of the datatable. The function is called whenever an ajax request causes a page change.



function initiateDataTableByAjax(tableObj) {    require(['datatables', 'datatables-tabletools'], function() {        tableObj.downLoadURL=/tabledbexport+tableObj.url.slice(/tabledb.length);        var table = $('#' + tableObj.id).dataTable({            paging : tableObj.isPaging,            ordering : tableObj.ordering,            dom : 'T
 
  lfrtip',            bProcessing : false,            aoColumnDefs : tableObj.aoColumnDefs? tableObj.aoColumnDefs:[{                aTargets: [ '_all' ],                mRender: function ( data, type, full ) {                    if(data!=null){                        return ''+data+'';                    }else{                            return '';                    }                }            }],            processing : true,            serverSide : true,            tableTools : {                sSwfPath : /bower_components/datatables-tabletools/swf/copy_csv_xls_pdf.swf,                aButtons : [{                    sExtends : xls,                    sTitle : tableObj.exportName,                    sAction : flash_copy,                    fnClick : function(nButton, oConfig, oFlash) {                        var params = table.fnSettings().aaSorting;//[0,asc]                        var search_value=table.fnSettings().oPreviousSearch.sSearch;                        var connector = ?draw=0&;                        if(tableObj.downLoadURL.indexOf(?)!=-1){                            connector = &draw=0&;                        }                        var export_url= tableObj.downLoadURL+connector+orderColumn=+params[0][0]+&orderDir=+params[0][1]+&search=+search_value;                        location.href = export_url;                    }                }]            },            ajax : {                url : tableObj.url,                error: function (xhr, error, thrown) {                    var wid = $('#' + tableObj.id).parents(.widget-content).parent().parent().attr(id);                    xhr.responseText = thrown;                    showErrorMsg(wid, xhr);                }            },                    columns : addAttributesForSomeColumns(tableObj.columnsSetting),            fnDrawCallback : function(oSettings) {                if(tableObj.fnDrawCallback){                    tableObj.fnDrawCallback();                }            }        });    });}function addAttributesForSomeColumns(columnsSetting) {    var columns_array = new Array();    if (columnsSetting.showColumns) {        for (i in columnsSetting.showColumns) {            var cc = {                data : columnsSetting.showColumns[i],            };            columns_array.push(cc);        };    } else {        for (var i = 0; i < columnsSetting.length; i++) {            var cc = {                data : i,            };            columns_array.push(cc);        };    }    if (columnsSetting.edit_columns) {        $.each(columnsSetting.edit_columns, function(index, element) {            columns_array[element[0]].data = null;            columns_array[element[0]].render = element[1];        });    };    return columns_array;}
 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.