Jay Roy
asked on
javascript : check for duplicates
hi experts
I am using EXT-Js 4.2 code to design some UI for my project.
I have set a renderer in my javascript code for a grid column
Any idea how firstnameRenderer() function above should change ?
Thanks
I am using EXT-Js 4.2 code to design some UI for my project.
I have set a renderer in my javascript code for a grid column
function firstnameRenderer(val) {
if(same firstname occurs twice , then color the two firstname with orange){
return '<span style="color:orange;">' + val + '</span>';
}else{
return val;
}
}
....
....
{
id:'myGrid',
xtype : 'grid',
stripeRows: true,
title: 'User Information',
store: Ext.data.StoreManager.lookup('mystore'),
autoHeight: true,
plugins: [ cellEditing ],
columns: [
{header: "First Name", width: 100, dataIndex: 'firstname', renderer: firstnameRenderer, sortable: true}
...
I want to check if a same firstname appears twice, if yes color it with orange.Any idea how firstnameRenderer() function above should change ?
Thanks
ASKER
I dont think so, i am using Ext-Js 4.2. Can you tell me how i can change the function
firstnameRenderer() in Ext-js
Thanks.
firstnameRenderer() in Ext-js
Thanks.
how is val formatted?
ASKER
sorry i dint get your question.
I have something like this working for me right nowas a test.
function firstnameRenderer(val) {
if(val == 'Angela') {
alert(val);
return '<span style="color:orange;">' + val + '</span>';
}else{
return val;
}
}
columns: [
{header: "First Name", width: 100, dataIndex: 'firstname', renderer: firstnameRenderer, sortable: true}
],
I have something like this working for me right nowas a test.
function firstnameRenderer(val) {
if(val == 'Angela') {
alert(val);
return '<span style="color:orange;">' + val + '</span>';
}else{
return val;
}
}
columns: [
{header: "First Name", width: 100, dataIndex: 'firstname', renderer: firstnameRenderer, sortable: true}
],
Hi,
here is a link on github for a way to elminate duplicates in a string
https://gist.github.com/lsauer/1305056
otherwise i would break the string down into parts and compare them
here is a link on github for a way to elminate duplicates in a string
https://gist.github.com/lsauer/1305056
otherwise i would break the string down into parts and compare them
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var maco = {};
function firstnameRenderer(val) {
if( maco[val] ) { // check if it already exists (return null if not)
maco[val] = true;
return '<span style="color:orange;">' + val + '</span>';
}
else {
return val;
}
}
ASKER
hi
I used the above code but looks like somethng is missing
I have
var maco = {};
function firstnameRenderer(val) {
alert(val);
if( maco[val] ) { // check if it already exists (return null if not)
alert('Inside if');
maco[val] = true;
return '<span style="color:orange;">' + val + '</span>';
}
else {
alert('Inside else');
return val;
}
}
val contain values
Angela
Michael
Michael
Kim
When val = Michael
alert('Inside if'); should pop up but its showing alert('Inside else');
I used the above code but looks like somethng is missing
I have
var maco = {};
function firstnameRenderer(val) {
alert(val);
if( maco[val] ) { // check if it already exists (return null if not)
alert('Inside if');
maco[val] = true;
return '<span style="color:orange;">' + val + '</span>';
}
else {
alert('Inside else');
return val;
}
}
val contain values
Angela
Michael
Michael
Kim
When val = Michael
alert('Inside if'); should pop up but its showing alert('Inside else');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks leakim971 and everyone.
ASKER
Any help with next question will be greatly appreciated
https://www.experts-exchange.com/questions/28510849/Grid-with-colored-columns.html
https://www.experts-exchange.com/questions/28510849/Grid-with-colored-columns.html
http://api.jquery.com/jquery.unique/