Search function not work data-search tag

Search function not work data-search tag

boraerelboraerel Posts: 4Questions: 2Answers: 0

my column Def;

columnDefs: [
{
data:"strikePrice",
targets: "strikePrice",
searchable: true,
render: function (data, type, full, meta) {

     if(data)
         return '<span style="display:none;">' + data + '</span>' + formatNumber(data, 2) + ' <span class="fs-12">(' + formatNumber(obj[code].strikePricePercent, 2) + '%)</span>';
     return '';
 }

}
]

when i try to search like this;
table.columns(12).search('22').draw();

result like this;

Where is my problem? Could you please help.

Thanks

Answers

  • boraerelboraerel Posts: 4Questions: 2Answers: 0

    I want to use data-search tag for searching.

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Is your table data sourced from the DOM, AJAX or Javascript?

    If not sourced from the DOM then Datatables won't use the data-search attribute.

    Since you are using columns.render can you use Orthogonal data to return the desired search value for the filter operation?

    I've seen some unexpected behavior when using data-search along with columns.render in the same column. Not sure they are meant to be used at the same time in the same column.

    Kevin

  • boraerelboraerel Posts: 4Questions: 2Answers: 0

    I am using json data source;
    table.rows.add(data).draw();

    Can you send me an example?

    Thanks

  • kthorngrenkthorngren Posts: 21,327Questions: 26Answers: 4,949

    Take a look at the computed values section of the Orthogonal data docs. You will probably want to do something like this:

        render: function ( data, type, row ) {
            // If display return data in the display format
            if ( type === 'display' ) {
                if(data)
                    return '<span style="display:none;">' + data + '</span>' + formatNumber(data, 2) + ' <span class="fs-12">(' + formatNumber(obj[code].strikePricePercent, 2) + '%)</span>';
                return ''; 
            }
    
            // If filter return data formatted for filtering
            if ( type === 'filter' ) {
                // Not sure what you want here so change return as required
                return Math.trunc( data );
            }
     
            // Otherwise the data type requested (`type`) is type detection or
            // sorting data, for which we want to use the integer, so just return
            // that, unaltered
            return data;
        }
    

    Kevin

Sign In or Register to comment.