Neotable y dar formato a una columna dependiendo el valor de otra, se puede? - Forum

Forum Navigation
You need to log in to create posts and topics.

Neotable y dar formato a una columna dependiendo el valor de otra, se puede?

Quiero mostrar el texto de una columna de determinado color dandole formato, pero el color va a depender del valor que esta en otra columna del mismo registro, ejemplo:

Columna 1 : Juan Manuel

Columna 2: 65

Lo muestro en el Card de la siguiente manera : Juan Manuel, 65 Años

Pero si la edad es mayor de 50 quiero mostrar todo el texto en rojo, incluyendo el nombre, no solo la edad, me explico

Lo mismo si la edad es menor a 50 mostrar todo el texto, incluyendo el nombre en Verde

MI pregunta es si se puede hacer eso en el format de Neotable de pasarle el valor de otra columna

@gustavo1973:

But if the age is over 50 I want to show all the text in red, including the name, not just the age

The way to approach this is to have a subroutine for both the fields.

a) examining the value of age in the subroutine for the Age column is straight forward.

b) in the subroutine for the Name column, obtaining the value of the Age column in the same row is a bit tricky; but take a look at this forum post ...

... Rocco (@roccocogliano) appears to have found an undocumented feature i.e. multiple values are being passed to the subroutine; using the json object and the index (row) values passed to the subroutine, you can extract the value of Age in the current row.

 

 

luishp and roccocogliano have reacted to this post.
luishproccocogliano

It's right. I solved it that way.
I had the exact same need as you: check the value of a field (in my case a battery and solar panel voltage value and similar values) and based on this value report the problem by coloring red (or green if that's all ok) a 'name' contained in another field on the same row.

Rocco

@roccocogliano

@gaev

Gracias , por la respuesta

algun ejemplo basico de como funciona o hacerlo no tienes?,

Hi @gustavo1973 in attached example (original neoTableTutorialPart1 example modified)  I added a subroutine called "fmtFirstName" where there is the use of what I said. It's visible in page titled "Controlled view". The column "First Name" is coloured with red using "Age" column value.

I hope it will be useful to you
Rocco

Uploaded files:
  • You need to login to have access to uploads.
luishp has reacted to this post.
luishp

@roccocogliano

@gaev

Hola, perdon la demora

estoy mirando tu ejemplo y hay cosas que no logro comprender, no logro hacerlo funcionar

A la subrutina se le pasan 3 valores por lo que veo, el objeto que contiene todos los datos cargados, el identificador "idx" del cual no veo donde se hace la definicion del mismo en el ejemplo, y se le pasa el valor que contiene ese campo en particular para darle formato. es esto correcto?

No veo donde se aplica al otro campo el color, en tu ejemplo la subrutina lleva al nombre para darle formato, pero antes toma el valor del campo "Age"

@gustavo1973

I do not see where the color is applied to the other field, in your example the subroutine takes the name to format it, but before it takes the value of the field "Age"

I took a look at the (modified) neoTableTutorialPart1 uploaded by @roccocogliano ... I noticed that he has a subroutine named fmtFirstName ... but it is not referenced in the Table definition ... try and change the column definition for "First Name" to include this subroutine, like so ...

neoTableSetColumn "SubroutinesContainer" 2 "name" "First Name" "" false false true "fmtFirstName"

... it will show the First Name in red color for those rows where Age is greater than 60

It invokes the neoTableGetData command to obtain the value of the Age filed for the current row (whose value is passed in the third parameter [idx].

The color is set in the style parameter within the < span > element returned from the subroutine.

 

 

roccocogliano has reacted to this post.
roccocogliano

@gaev

@gustavo1973

the function is just what @gaev says and is used in the "Load data" button of the "Views" page

Uploaded files:
  • You need to login to have access to uploads.

@roccocogliano

is used in the "Load data" button of the "Views" page

My apologies, I was looking at the Subroutines page

@gustavo1973 - does this answer your question ?

roccocogliano has reacted to this post.
roccocogliano