EasyUI Forum
April 26, 2024, 06:09:22 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Highlight searched text in datagrid cell [Solved]  (Read 5786 times)
Darrel
Jr. Member
**
Posts: 74


View Profile
« on: March 28, 2018, 09:16:09 AM »

Hello team,

Is it possible to highlight the searched term in the doSearch function for a single search field on the grid?? For example, if I type 'ABCD' and if the data is present in the row object, then change the font color to red and background color to yellow of that matching cell.

The code is the same as the following link: https://www.jeasyui.com/forum/index.php?topic=5537.0

Code:
function doSearch(inp) {
var rows = [];

inp = inp.toUpperCase();

var l_pageSize = $('#dg').datagrid('options').pageSize;

if(!table_data.length || l_pageSize != g_pageSize)
{
getTableData();
}

$.map(table_data, function(row){
for(var p in row)
{
var v = row[p];
var regExp = new RegExp(inp, 'i'); // i - makes the search case-insensitive.

if(regExp.test(String(v)))
{
//will I have to manipulate the rows here???
rows.push(row);
break;
}
}
});

if(inp != "")
{
alert("Found records: " + rows.length);
$('#dg').datagrid('loadData', rows);
}
}

Thanks & Regards,
Darrel
« Last Edit: April 02, 2018, 04:55:17 AM by Darrel » Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #1 on: March 28, 2018, 06:28:47 PM »

To highlight the cells, you should define the 'styler' property on each column.
Code:
var regExp = null;
function doSearch(value){
regExp = value ? new RegExp(value, 'i') : null;
var data = $('#dg').datagrid('getData');
$('#dg').datagrid('loadData', data);
}
function cellStyler(value,row,index){
if (!regExp){return;}
value = String(value || '');
if (regExp.test(value)){
return 'color:red';
}
}

For more information please look at this example http://code.reloado.com/elexay3/edit#html,live
Logged
Darrel
Jr. Member
**
Posts: 74


View Profile
« Reply #2 on: April 02, 2018, 04:55:02 AM »

Hi jarry,

Thanks a lot for your reply. I've modified the code slightly as per my requirements.
The modified reloado code for the same is: http://code.reloado.com/elexay3/5/edit

Regards,
Darrel
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #3 on: April 03, 2018, 11:31:33 PM »

Thanks jerry for your beautiful example. If I want automatic datagrid refresh with each keystorke in searchbox, rather than pressing search icon at the right side of search-box what modification I have to do?
Logged
jarry
Administrator
Hero Member
*****
Posts: 2262


View Profile Email
« Reply #4 on: April 04, 2018, 05:29:00 PM »

You can press ENTER to do the same as clicking the search icon.
Logged
thecyberzone
Full Member
***
Posts: 176



View Profile Email
« Reply #5 on: April 06, 2018, 01:14:29 AM »

Actually what I want, just to filter the datagrid output according to the keystroke of serachbox.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!