DataTable parameters and service-side AJAX function Configuration and description __ function

Source: Internet
Author: User
Last week, because of the need to use a DataTable, but online search is either a little bit of parameter introduction, or is a few callback function introduction, very few have more comprehensive, so put their own summed up a bit, which involves the service side of the page, in fact, the DataTable has been integrated into our , it is very convenient to use, words do not say much, as follows: about the use of DataTable: 1, basic parameter configuration:
It should be noted that the Table object to be processed by the DataTable must have Thead and tbody, and that the structure should be structured (the data is not necessarily complete) so that it can be handled correctly. The following are the parameters that can be attached when a datatable binding process is performed:

Property name Take value range Explain
Bautowidth True or FALSE, default True Whether to automatically calculate the width of columns in a table
Bdeferrender True or FALSE, default false One of the parameters for rendering
Bfilter True or FALSE, default True switch, whether to enable the client filtering function
Binfo True or FALSE, default True switch, whether to display some information about the table
Bjqueryui True or FALSE, default false Do you want to use the jquery UI Themeroller style
Blengthchange True or FALSE, default True switch, whether to display a selection bar per page length (requires pager support)
Bpaginate True or FALSE, default True switch, whether to display (use) the page splitter
Bprocessing True or FALSE, Defualt false Switch to specify whether to display the "processing" message when the data is being processed
Bscrollinfinite True or FALSE, default false Switch to specify whether unlimited scrolling (used with sscrolly) is useful in large amounts of data. When this flag is true, the pager closes by default
Bsort True or FALSE, default True Switch to let each column have the ability to sort by column
Bsortclasses True or FALSE, default True Switch that specifies whether to increase the classes ' sorting_1 ', ' sorting_2 ' and ' sorting_3 ' when the current column is sorted, and when it is turned on, the performance is lost when processing large data
Bstatesave True or FALSE, default false Switch, whether to turn on the client state logging feature. This data is recorded in cookies, after opening the record, even if you refresh the page, or reopen the browser, before the state is saved
Sscrollx Strings similar to ' disabled ' or ' 100% ' Whether to turn on horizontal scrolling and specify the size of the scrolling area
Sscrolly String similar to ' disabled ' or ' 200px ' Whether to turn on vertical scrolling and specify the size of the scrolling area
-- -- --
Options
Aasorting Array array[int,string], as [], [[0, ' ASC '], [0, ' desc ']] Specify the basis for sorting by multiple columns of data
Aasortingfixed Ditto Ditto. The only difference is that the user's custom configuration does not conflict.
Alengthmenu Default [10, 25, 50, 100] can be a one-dimensional array, or a two-dimensional array, for example: [[X, C,-1], [ten, X, all]] This is to select the number of entries per page, when using a two-dimensional array, the two-dimensional level can only have two elements, the first is to display the number of entries per page options, the second is about the interpretation of these options
Aosearchcols Default NULL, similar to: [NULL, {"Ssearch": "My Filter"}, null,{"Ssearch": "^[0-9]", "Bescaperegex": false}] Individually define their initialization search list attributes for each column (this piece is not yet understood)
Asstripclasses default [' odd ', ' even '], such as [' Strip1 ', ' strip2 ', ' STRIP3 '] Specifies the class style to be applied to each row and automatically loops
Bdestroy True or FALSE, default false Used when you want to perform a new DataTable binding on the same element, clear the previous data object and swap it with the new object settings
Bretrieve True or FALSE, default false Used to indicate whether a DataTable object is returned when a DataTable binding is performed
Bscrollcollapse True or FALSE, default false Specify the appropriate time to indent the scrolling view
Bsortcellstop True or FALSE, default false (Unknown Dongdong)
Icookieduration Integer, default 7200, per second Specifies the length of time used to store client information in a cookie, which expires automatically after this time
Ideferloading Integer, default is null Deferred loading, which is the number of items to load, usually used in conjunction with Bserverside,sajaxsource, etc.
Idisplaylength Integer, default is 10 To specify the number of bars to display on a screen, you need to open the page splitter
Idisplaystart Integer, default is 0 Used to specify which data to start showing to the table
Iscrollloadgap Integer, default is 100 Used to specify how many data can be displayed at most one screen when the DataTable is set to scroll
OSearch Default {"Ssearch": "", "Bregex": false, "Bsmart": true} is also the initial time to specify the search parameters related, a little complicated, do not understand the current
Sajaxdataprop String, default ' Aadata ' Specifies the name used by the data item when obtaining tabular data from the server
Sajaxsource URL string, default null Specify which URL to get the data from
Scookieprefix String, default ' Sprymedia_datatables_ ' The prefix name used to specify the string stored in the cookie when the state store attribute is turned on
Sdom Default Lfrtip (when Bjqueryui are false) or < "H" lfr>t< "F" ip> (when Bjqueryui is true) This is a powerful attribute for defining the DataTable layout, and a separate document is added to the description.
Spaginationtype ' Full_numbers ' or ' Two_button ', default ' Two_button ' Used to specify the pager style
Sscrollxinner String Default ' disabled ' It's related to horizontal scrolling, not knowing what it means.



For the server, the current operation information can be obtained by requesting parameters. [This means that the property values in the following list are available in the server-side method. These can be obtained in aodata in the following example


Type Name Description
Int Idisplaystart The starting index to display
Int Idisplaylength Number of rows displayed
Int Icolumns Number of columns displayed
String Ssearch Global Search Fields
Boolean Bescaperegex Whether the global search is regular
Boolean Bsortable_ (int) Indicates whether a column can be sorted at the client's flag bit
Boolean Bsearchable_ (int) Indicates whether a column can be searched at the client's flag bit
String Ssearch_ (int) Search for individual columns
Boolean bescaperegex_ (int) Whether a regular search is used for individual columns
Int Isortingcols Number of columns sorted
Int Isortcol_ (int) Sorted columns
String Ssortdir_ (int) The direction of the sort is "desc" or "ASC".
String Secho Information that DataTables uses to generate


The data format returned by the server is shown below
Type Name Description
Int Itotalrecords Actual number of rows
Int Itotaldisplayrecords After filtering, the actual number of rows.
String Secho The unchanged copy from the client Secho,
String Scolumns Optionally, a comma-delimited column name,
Array array Mixed Aadata An array of arrays, the actual data in the table.

callback Function name Parameters return value Default Function
Fncookiecallback 1.string:name of the cookie defined by DataTables 2.object:data to is stored in the cookie 3.string:cookie expires Ng 4.string:path of the cookie to set String:cookie formatted string (which should is encoded by using encodeURIComponent ()) Null This function call is triggered when each cookie is changed
Fndrawcallback No No No Call after each table is draw, as far as what to do to see do it
Fnfootercallback 1.node: "TR" element for the footer 2.array array strings:full table data (as derived from the original HTML) 3.int:i Ndex for the "current display starting" in "Display array< 4.int:index for the" current display ending point in The display array 5.array int:index array to translate the visual position to the full data array No No Used to modify the foot of a table each time you repaint
Fnformatnumber 1.int:number to be formatted string:formatted string for DataTables to show the number Have the default Used in large numbers, automatically add some commas, separate
Fnheadercallback 1.node: "TR" element for the header 2.array array strings:full table data (as derived from the original HTML) 3.int:i Ndex for the "current display starting" the "Display array 4.int:index for" The current display ending the Display array 5.array int:index array to translate the visual position to the full data array No No Used to modify the header of a table each time the draw occurs
Fninfocallback 1.object:datatables Settings Object 2.int:starting position in data for the draw 3.int:end position in data for the DRA W 4.int:total number of rows in the table (regardless of filtering) 5.int:total number of rows in the data set, after fi Ltering 6.string:the String that DataTables has formatted using it ' s own rules String:the string to is displayed in the information element. No Used to communicate table information
Fninitcomplete 1.object:osettings-datatables Settings Object No No Called after table initialization completes
Fnpredrawcallback 1.object:osettings-datatables Settings Object Boolean No Used to invoke before the start of the drawing, to return false, to prevent draw events from occurring, and to return other values, draw can be executed smoothly
Fnrowcallback 1.node: "TR" element for the current row 2.array Strings:raw data array for this row (as derived from the original HTML 3.int:the Display index for the current table draw 4.int:the Index of the the ' data in the ' full list of rows (after Filte Ring Node: "TR" element for the current row No Called when a row is created but not yet drawn to the screen, typically used to change the class style of a row
Fnserverdata 1.string:http source to obtain the data from (i.e. Sajaxsource) 2.array objects:a key/value pair object containing the D ATA to send to the server 3.function:function to is called on completion of the ' data get process ' that'll draw the data On the page. void $.getjson Used to replace the default request action sent to the service side
Fnstateloadcallback 1.object:osettings-datatables Settings Object 2.object:odata-object containing information retrieved to the State SA Ving Tsun cookie which should be restored. For the exact properties please refer to the DataTables code. Boolean-false if the state should is loaded, true otherwise No The data in the cookie is executed before it is loaded and can be easily modified
Related Article

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.