Search is not working on cells that use 'fnCreatedCell'

Search is not working on cells that use 'fnCreatedCell'

caldera500caldera500 Posts: 2Questions: 1Answers: 0
edited July 2016 in Free community support

The table content gets created as intended. I am just noticing that columns where I manipulate the content with 'fnCreatedCell' are not included in search results. Search works on all other columns:

$('#user_table').DataTable({    
   ajax: {
    url: '/load_users',
    dataSrc: ''
 },
 columns: [
    {data: '_id',
     "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                 $(nTd).html('<div class="userdetail" rel="' +oData._id+ '">' +oData.firstName+ ' ' +oData.lastName+  '</div>');
     }},

    {data: 'local.email'},
    {data: '_id'}
       ]
 });

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin
    Answer ✓

    This is correct - it would be exceptionally slow for DataTables to read the DOM for the text to search whenever a search was made, so it uses a cache (it can also search data before the columns.createdCell callback is called as well!).

    You need to use orthogonal data, as described in the manual.

    Regards,
    Allan

  • caldera500caldera500 Posts: 2Questions: 1Answers: 0

    Thank You Allan! That pointed me in the right direction.

    So to show multiple values from the json data source in a single table cell I introduced a function in columns.render. It is important to use null as a data source for this column so all object parameters are available.

        columns: [
        {
            data: null,
            render: function(d) {
                return d.firstName + ' ' + d.lastName;
            }
    

    },

  • allanallan Posts: 61,853Questions: 1Answers: 10,134 Site admin

    Looks good to me :smile:

    Allan

This discussion has been closed.