Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I had defined the row style in the records, but is invalid #1372

Closed
chenduansheng opened this issue Nov 7, 2016 · 16 comments
Closed

I had defined the row style in the records, but is invalid #1372

chenduansheng opened this issue Nov 7, 2016 · 16 comments

Comments

@chenduansheng
Copy link

chenduansheng commented Nov 7, 2016

Hi, I meeted a bug,
I had defined the row style ["background-color: red"] in the records, but is invalid.
see http://jsfiddle.net/api/post/jquery/2.1/

@spizzi77
Copy link

spizzi77 commented Nov 7, 2016

I don't see the code in the jsfiddle...

@chenduansheng
Copy link
Author

sorry, I make a error
the right url is : http://jsfiddle.net/ya9eerb5/

@spizzi77
Copy link

spizzi77 commented Nov 7, 2016

I think you must use the render on columns....

        columns: [                
            { field: 'fname', caption: 'First Name', size: '50%', render:function(record){
   return '<div style="background-color:red">'+record.fname+'</div>';
} },
            { field: 'sdate', caption: 'Dates', size: '50%' }
        ],

@chenduansheng
Copy link
Author

thanks,
I try it, but it still no color, see http://jsfiddle.net/ya9eerb5/1/

@spizzi77
Copy link

spizzi77 commented Nov 7, 2016

Sorry, the last update it's right, the render is in columns not in recid.... ;)

@chenduansheng
Copy link
Author

thank you for the quickly help,
just now i try the old version of 1.4.2, 1.4.2 is no problem
but version of 1.5 has the problem and i use 1.5 currently

@spizzi77
Copy link

spizzi77 commented Nov 7, 2016

Yes but in fact i said a think not true, or better you can use style again...
columns: [
{ field: 'fname', caption: 'First Name', size: '50%' ,style:'background:red'},
{ field: 'sdate', caption: 'Dates', size: '50%' }
]

;) Bye

@chenduansheng
Copy link
Author

thanks,
the version 1.5 has problem, see http://jsfiddle.net/ya9eerb5/
and the version 1.4.2 is good, see http://jsfiddle.net/q3drbpvn/

image

@mpf82
Copy link
Collaborator

mpf82 commented Nov 8, 2016

In 1.5, w2ui specific properties need to be moved to a w2ui: {} property:

    { "recid": 2, "fname": "Ludwig Van", "sdate": "1770-1827", w2ui: { "style": "background-color: red" } }

Updated fiddle: http://jsfiddle.net/ya9eerb5/2/

See also my answer in this thread

Cheers :)

@chenduansheng
Copy link
Author

thanks, I try it, and now it works perfectly.

By the way, i suggest that the 'render' function can work on the row, not only on the cell. i know there is already a cell 'render' function. but sometimes we need to control a row, not only a cell, for example: i have a list of persons in w2ui grid and i want to do this:

//if age less than 10, to make the row's color is red; if age less than 18,to make the row's color is yellow...
if( record.age<10 ){
record.w2ui = { "style": "background-color: RED" };
} else if ( record.age<18 ){
record.w2ui = { "style": "background-color: YELLOW" };
} else {
... ...
}

because the broswer reg data from the remote server, and i want the data's volume be less.
the above way will make's the server no longer need to return the data of 'w2ui{"style:....."}' because it would be made by w2grid, so it will save more server resources and save more network transmission.

thanks again.

@mpf82
Copy link
Collaborator

mpf82 commented Nov 8, 2016

You can already do this if you define a column renderer and in the renderer change the style of the record row based on the record's data:

http://jsfiddle.net/ya9eerb5/5/

@mendozada
Copy link
Contributor

Hello, as I would have to change the background only to a specific cell or cells in version 1.5
i use php

`
$con=0;
$acum = 0;
while($row = mysql_fetch_array($result)) {
$con++;
$acum += $row['Cantidad'];
//array del grid con los registros de remitos correctos
$datos[] = array(
'recid' => $con, //identificador para el grid
'FechaRemito' => str_replace('-', '/',date("d-m-Y", strtotime($row['FechaRemito']) )), // Transformo la fecha
'NroRemito' => $row['NroRemito'],
'IdArticulo' => $row['IdArticulo'],
'Descripcion' => $row['Descripcion'],
'Cantidad' => ''.$row['Cantidad'].'',
'IdPersonal' => $row['IdPersonal'],
'Legajo' => $row['Legajo'],
'ApeNom' => utf8_encode($row['ApeNom']),
'Observaciones' => utf8_encode($row['Observaciones']),
'style' => 'background-color: #C2F5B4;',

                    );  

}

`
but don't work 'style' => 'background-color: #C2F5B4;',

@chenduansheng
Copy link
Author

@mpf82 thank you very much, it perfectly help me, good luck!

@mpf82
Copy link
Collaborator

mpf82 commented Nov 8, 2016

@mendozada: this has already been covered in this thread. Instead of record.style = "..." you need to use record.w2ui.style = "..."

I don't know how to explain this in PHP, so please understand the following as pseudo code:

$datos[] = array(
    'recid' => $con, //identificador para el grid
    ...
    'w2ui' => array(
        'style' => 'background-color: #C2F5B4;'
    )
)

Maybe someone who knows PHP can help out with the correct syntax.


@chenduansheng: If the issue is resolved for you, please close the thread :)

@chenduansheng
Copy link
Author

the issue is resolved the problem

@sveco
Copy link

sveco commented Aug 8, 2017

You jsfiddle does not work if you sort by some column, everything is reset to default style. In latest W2UI version if I set:
record.w2ui.style = { 4: 'background-color: #FBDCA2' }; // the cell in 5th column is colored, but if I set
record.w2ui.style = 'background-color: #C2F5B4'; // the row style is not applied until I refresh grid in some way (e.g. by reordering coluymn), after that it colors the row green

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants