DataTables logo DataTables

via Ad Packs
Highlight term returned from search
  • 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.
    $('#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, '<span class=\'hightlight\'>' + txt + '</span>'));
    					});
    		
    					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_"
    			}
    		});
  • allanallan
    Posts: 10,309
    Have a look at this post, which shows one way how this feature could be implemented: http://datatables.net/forums/discussion/8370/upgrading-from-1.8-1.9-issues#Item_2

    Allan

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Support

Get useful and friendly help straight from the source.

In this Discussion