Highlight term returned from search
Highlight term returned from search
yhbrandon
Posts: 1Questions: 0Answers: 0
Im hoping that someone could help me out on this issue I'm having with trying to highlight a value in a column once it is returned from a search. Basically I have three columns to my datatable, Name, type, and an action field. Once a user search for a particular name, all items with that name are returned in the table. I want to be able to highlight the name that is return from the search in the name column. So basically every name will be highlighted. This is what I'm during currently without much success. Any help would be greatly appreciated.
[code]
$('#TBLfindDict').dataTable({
"iDisplayLength": 100,
"sPaginationType": "full_numbers",
"bLengthChange": false,
"bFilter": false,
"bJQueryUI": true,
"sAjaxSource": /path/,
"sAjaxDataProp": "data",
"fnRowCallback": function(data, iDisplayIndex, iDisplayIndexFull){
var txt = $('#txtHighlight').val();
var txtRegex = new RegExp(txt, "g");
$('#results .termFlag').each(function(){
$(this).html($(this).html().replace(txtRegex, '' + txt + ''));
});
return data;
},
"aoColumns": [
{ "mDataProp": "name" },
{ "mDataProp": "type" },
{ "mDataProp": "id",
"bSortable": false,
"fnRender": function ( oObj ) {
return /path/;
}
}
],
"oLanguage": {
"sZeroRecords": "No Records",
"sInfo": "_START_-_END_ of _TOTAL_"
}
});[/code]
[code]
$('#TBLfindDict').dataTable({
"iDisplayLength": 100,
"sPaginationType": "full_numbers",
"bLengthChange": false,
"bFilter": false,
"bJQueryUI": true,
"sAjaxSource": /path/,
"sAjaxDataProp": "data",
"fnRowCallback": function(data, iDisplayIndex, iDisplayIndexFull){
var txt = $('#txtHighlight').val();
var txtRegex = new RegExp(txt, "g");
$('#results .termFlag').each(function(){
$(this).html($(this).html().replace(txtRegex, '' + txt + ''));
});
return data;
},
"aoColumns": [
{ "mDataProp": "name" },
{ "mDataProp": "type" },
{ "mDataProp": "id",
"bSortable": false,
"fnRender": function ( oObj ) {
return /path/;
}
}
],
"oLanguage": {
"sZeroRecords": "No Records",
"sInfo": "_START_-_END_ of _TOTAL_"
}
});[/code]
This discussion has been closed.
Replies
Allan