Page 1 of 1

Conditional formatting

Posted: Thu May 05, 2022 2:17 pm
by acroporax
Hi all,

Code: Select all

function browseConditionalFormatting() {
    $('[data-nu-column="1"]').each(function (index) {
        var v = $(this).html();
        var color = String(v) == "TOPLAM" ? 'yellow' : '';
        $(this).css("background-color", color);
    });
}
This code working for 1 column, but i want change to color data-nu-column="2 and data-nu-column="1" together. But conditinal if must look only data-nu-column="1" How to make?

Re: conditinal formating

Posted: Thu May 05, 2022 2:23 pm
by kev1n
Hi,

Do you mean that column 1 + 2 should get the bg color yellow if the value in column 1 is TOPLAM?

Re: conditinal formating

Posted: Thu May 05, 2022 2:40 pm
by acroporax
kev1n wrote: Thu May 05, 2022 2:23 pm Hi,

Do you mean that column 1 + 2 should get the bg color yellow if the value in column 1 is TOPLAM?

Correct.

Re: conditinal formating

Posted: Thu May 05, 2022 2:52 pm
by kev1n
Give this a try:

Code: Select all

function browseConditionalFormatting() {
    $('[data-nu-column="1"]').each(function (index) {
        let v = $(this).html();
        let color = String(v) == "TOPLAM" ? 'yellow' : '';
	let bg = {"background-color": color};
        $(this).css(bg).next().css(bg);
    });
}

Re: conditinal formating

Posted: Thu May 05, 2022 3:10 pm
by acroporax
kev1n wrote: Thu May 05, 2022 2:52 pm Give this a try:

Code: Select all

function browseConditionalFormatting() {
    $('[data-nu-column="1"]').each(function (index) {
        let v = $(this).html();
        let color = String(v) == "TOPLAM" ? 'yellow' : '';
	let bg = {"background-color": color};
        $(this).css(bg).next().css(bg);
    });
}
Thank you so much,

Re: Conditional formatting

Posted: Wed Jan 25, 2023 9:23 am
by acroporax
Hi Again,

I am using the above code, thanks a lot. But how can i column1 < column2 result Red..

Re: Conditional formatting

Posted: Wed Jan 25, 2023 9:37 am
by kev1n
Do column 1 + 2 contain numeric values?
If the value in column 1 is smaller than the one in column 2, column 1 (or 2?) should be red?
Or is the logic different?

Re: Conditional formatting

Posted: Wed Jan 25, 2023 10:37 am
by acroporax
Example;
column1 = "Customer Name"
column2 = "2022 sales of year"
column3 = "2023 Sales of year"

column1 = "Michele"
column2 = "10 $"
column3 = "20 $"


if (column3 <column2)
{ column1.background=red}

Re: Conditional formatting

Posted: Wed Jan 25, 2023 11:09 am
by kev1n
As long as there are no negative numbers, this should do the job:

Code: Select all

$("[data-nu-column='1']").each(function(index) {

	const c1Value = this.innerText.justNumbers();
	const c2Value = this.nextSibling.innerText.justNumbers();	
	
	const color = c2Value < c1Value ? 'red' : '';
	const bg = {"background-color": color};
	$(this.previousSibling).css(bg);

});

Re: Conditional formatting

Posted: Wed Jan 25, 2023 2:50 pm
by acroporax
it's working well, thanks..