[SOLVED] Searchable Columns
[SOLVED] Searchable Columns
organicspider
Posts: 12Questions: 0Answers: 0
Making great headway with DataTables and its awesome :D
I have generated a table that includes two telephone numbers; inbound and outbound. Based on a separate column I decide which number to be show[code]var sDirectionClass; var sSrc = aData[3]; var sDst = aData[4];
if ( aData[1] == "0" ) {
sDirectionClass = "inbound"; $('td:eq(2)', nRow).html( sSrc );
$('td:eq(1)', nRow).html( '' );
} else {
sDirectionClass = "outbound"; $('td:eq(2)', nRow).html( sDst );
$('td:eq(1)', nRow).html( '' );
}[/code] Is it possible to exclude the sSrc and sDst columns from the search but allow the resulting column to be included. The rationale is that if you search for a specific number it could be the source when what is being displayed is the destination; confusing :)
I have generated a table that includes two telephone numbers; inbound and outbound. Based on a separate column I decide which number to be show[code]var sDirectionClass; var sSrc = aData[3]; var sDst = aData[4];
if ( aData[1] == "0" ) {
sDirectionClass = "inbound"; $('td:eq(2)', nRow).html( sSrc );
$('td:eq(1)', nRow).html( '' );
} else {
sDirectionClass = "outbound"; $('td:eq(2)', nRow).html( sDst );
$('td:eq(1)', nRow).html( '' );
}[/code] Is it possible to exclude the sSrc and sDst columns from the search but allow the resulting column to be included. The rationale is that if you search for a specific number it could be the source when what is being displayed is the destination; confusing :)
This discussion has been closed.
Replies
So what I would suggest is a little change of plan and to use fnRender instead, which will allow your data to be filtered (you can remove the two source columns from the filter using bSearchable). Now the disadvantage in this case is the fnRender will run only once during the life time of a row (at creation), unless the row is updated. So if you have something which is toggled by the user to select which is being shown, then you'll need to update each row, forcing the render again. If however the decision for what to display is made before the table is initialised and won't change, then fnRender is most certainly the easiest way to go.
Please shout if anything needs clarified - hope this helps!
Regards,
Allan
I must be doing something wrong as it still does not work for me :( I have moved the code from fnRowCallback into fnRender[code]"aoColumnDefs": [ { "sClass": "center", "aTargets": [ 0, 1, 2, 3, 4, 5, 6, 7] } ],
"aoColumns": [
null,
{ "bSearchable": false },
{ "fnRender": function ( oObj ) { if ( oObj.aData[1] == "0" ) { return oObj.aData[3]; } else { return oObj.aData[4]; } } },
{ "bVisible": false, "bSearchable": false, },
{ "bVisible": false, "bSearchable": false },
null,
null,
null
],[/code]Any ideas ?
Allan
Yep the third column is being populated correctly. An example of what I am seeing is say with the following data:
src dst Number (3rd column)
--- ---- -------------------------
01234 789 01234
02345 456 456
01234 234 01234
If I enter 789 in the search field it filters the first record; which is confusing to the user as they only see 01234 on the screen.
Allan