Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Conditional formatting Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Conditional formatting

Unread post 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?
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: conditinal formating

Unread post by kev1n »

Hi,

Do you mean that column 1 + 2 should get the bg color yellow if the value in column 1 is TOPLAM?
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Re: conditinal formating

Unread post 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.
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: conditinal formating

Unread post 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);
    });
}
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Re: conditinal formating

Unread post 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,
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Re: Conditional formatting

Unread post by acroporax »

Hi Again,

I am using the above code, thanks a lot. But how can i column1 < column2 result Red..
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Conditional formatting

Unread post 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?
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Re: Conditional formatting

Unread post 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}
kev1n
nuBuilder Team
Posts: 4297
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 445 times
Contact:

Re: Conditional formatting

Unread post 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);

});
acroporax
Posts: 42
Joined: Thu Apr 21, 2022 3:04 pm
Has thanked: 5 times
Been thanked: 1 time

Re: Conditional formatting

Unread post by acroporax »

it's working well, thanks..
Post Reply