Incorrectly detecting plain html as html-num

Incorrectly detecting plain html as html-num

travelnsamtravelnsam Posts: 2Questions: 1Answers: 0

Link to test case: https://live.datatables.net/bakeweji/1/edit
Debugger code (debug.datatables.net): N/A
Error messages shown: N/A
Description of problem:

If html is used that only consists of tags, and no content, it is 'detected' as html-num. An example of where HTML like this might be used is, perhaps, one or more icons from a library like Font Awesome being used in the table as links eg:

<a href="#"><i class="fa fa-home"></i></a><a href="#"><i class="fa fa-envelope"></i></a>

The end result is that this gets assigned type of dt-type-numeric, with associated impacts such as right alignment. I am not sure if this is by design? Nor whether or not it is new with DataTables 2 (we are trying to upgrade from a much older version, where this did not happen.)

It looks like the tags are all stripped, leaving the compare data 'empty' which then triggers a match here:

var _htmlNumeric

When it checks for numeric here:

_isNumber( _stripHtml( d ), decimalPoint, formatted ) ? true : null;

This returns 'true', because d is now empty (everything got stripped), and _isNumber returns 'true' for empty values here:

// If empty return immediately so there must be a number if it is a
// formatted string (this stops the string "k", or "kr", etc being detected
// as a formatted number for currency
if ( _empty( d ) ) {
     return true;
}

I prepared a small test case showing this. If you inspect the 'html' column, you can see dt-type-numeric is applied, and therefore right alignment. (The cells themselves are blank, as Font Awesome is not loaded, but you can still see the type class applied, and alignment on the header/footer.)

Sam

Answers

  • allanallan Posts: 61,972Questions: 1Answers: 10,160 Site admin

    Hi Sam,

    Thanks for your report and investigation. My current plan to address this is to introduce a second type detection function on DataTables 2.1 which will be a stricter "at least one must match this" type function. In the case of numbers it would mean that at least one cell must contain a number, rather that saying that all cells which are empty (after the html stripping).

    I don't expect 2.1 to be to far way - maybe a couple of months. This feature will be added before then though I'm sure, as it is very much on my mind.

    Allan

  • travelnsamtravelnsam Posts: 2Questions: 1Answers: 0

    OK thanks for the rapid feedback, Allan. Most appreciated. I will keep an eye out for this being added, and try some form of workaround in the interim.

    Sam

Sign In or Register to comment.