In-depth analysis of DataTable Filtering

Source: Internet
Author: User

In-depth analysis of DataTable Filtering

This DataTable refers to the page plug-in designed and developed by SpryMedia for HTML Table. The official site is http://legacy.datatables.net/index.

About oSettings. aiDisplayMaster, oSettings. aiDisplay and oSettings. aoData

Whether it is row data obtained from JSON or row data obtained from DOM elements, the data is stored in oSettings. aoData after the table is initialized. The number of records in the aoData array is long.

The aiDisplayMaster is used to record the position of each row of data in aoData after sorting by column. This sorting process is arranged in the _ fnSort () method.

Not all data in each row needs to be displayed, so aiDisplay is used to save the row records to be displayed and their locations. AiDisplay comes from aiDisplayMaster and is a subset after aiDisplayMaster is sorted.

If filter is not used, aiDisplay is equal to aiDisplayMaster.

Filter

The so-called filtering is actually from the aiDisplayMaster. According to the aoData data and matching conditions, the sequence numbers of the row data to be displayed are stored in the aiDisplayMaster array in the sorted order.

Filters are classified into global filtering, column-based filtering, and custom filtering.

Filtering is performed in the _ fnFilterComplete () method. The execution sequence is global filtering, column-based filtering, and custom filtering. These three filters correspond to: _ fnFilter (), _ fnFilterColumn (), and _ fnFilterCustom ().

Global Filtering

Global filtering is divided into forced re-filtering and non-forced re-filtering. The so-called forced re-filtering means that the aiDisplay array is completely re-created. Instead of force re-filtering, the data is further filtered based on the previous aiDisplay.

Note that if the global filter string is null, aiDisplay equals to aiDisplayMaster.

Forced global filtering is used in the following scenarios:

  • Call the fnFilter () method, whether or not column is specified;
  • Directly call _ fnFilter (oSettings, sInput, 1 );
  • Call the _ fnSort () method;
  • Call the _ fnFilterComplete () method, but the filter string is empty.

The use of unforced global filtering includes:

  • Call the _ fnReDraw () method;
  • Call the _ fnInitialize () method, that is, when initializing;
Column-Based Filtering

After global filtering, the column is filtered out. The column filtering is performed on aiDisplay, The result set of global filtering, and then the row data sequence numbers that do not need to be displayed are filtered out.

Column Filtering is based on the string returned when type = filter in the mRender column.

Column Filtering is performed in the _ fnFilterColumn method.

Custom Filtering

Custom filtering is the last step of filtering. It is further filtering the aiDisplay result set of Column Filtering. The method used for this filtering needs to be defined in the DataTable. ext. afnFiltering array.

Each custom filtering method accepts three parameters (from left to right ):

  • OSettings;
  • Row data;
  • Row serial number;
Multi-Keyword Filtering

The fnFilter method has a bSmart parameter. If this parameter is set to true, spaces between keywords are used as separators.

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.