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