jquery DataTable No data hint not centered display

Source: Internet
Author: User

Original address: https://www.jianshu.com/p/fc4784d11722

Yesterday, a problem was encountered, the table generated by the DataTable has no data, but "no-data found" is not centered, the root cause is that the Clospan property value is not set correctly. Find out that this problem only appears in tables that are not visible at render time.

Solution: Change the source code of Jquery.dataTables.js. return$ (_pluck (osettings.aocolumns, ' nTh ')). Filter (': Visible '). length; This step returns the number of visible columns, changed to return$ (_pluck ( Osettings.aocolumns, ' nTh '). Length; Returns the number of all columns. If you take this approach, make sure that you do not affect other features.

Through a long period of research, the problem of jquery Datatables.js is determined. The logic generated when the empty data is found. The source code is as follows:

/* Table is empty-create a row with an empty message in it */

Varszero=olang.szerorecords;

if (Osettings.idraw==1&&_fndatasource (osettings) = = ' Ajax ')

{

Szero=olang.sloadingrecords;

}

else if (olang.semptytable&& osettings.fnrecordstotal () ===0)

{

szero=olang.semptytable;

}

Key code:

' valign ': ' Top ',

' ColSpan ': _fnvisblecolumns (osettings),

' Class ': OSettings.oClasses.sRowEmpty

}). html (szero)) [0];

This is the property that you always look for, and how you define it when you look at the function. Look at the name and know it should be related to the visible column. More proof of my speculation.

/**

* Get the number of the visible columns

* @param {Object} osettings dataTables Settings object

* @returns {int} i the number of visible columns

* @memberofDataTable #oapi

*/

Function_fnvisblecolumns (osettings)

{

return$ (_pluck (osettings.aocolumns, ' nTh ')). Filter (': Visible '). Length;

}

Here we have finally found the cause of the problem, the original DataTable Clospan property is to get the number of all visible columns. If the table is hidden at that time, then the number of visible columns is naturally 0, so the Clospan property is set to 0. When the table is visible again, the value of colspan is 0, so the message is not centered.

jquery DataTable No data hint not centered display

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.