This is a migrated thread and some comments may be shown as answers.

How do I format a grid cell based on its value compared to another cell?

3 Answers 345 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AkAlan
Top achievements
Rank 2
AkAlan asked on 29 Jun 2012, 12:44 AM
I want to compare a column (QtyReceived) to another column (QtyShipped) and change the background color of the QtyReceived column if it is less than QtyShipped. I need to be able to do the compare when the grid is first fired then after the user edits the QtyReceived column.

3 Answers, 1 is accepted

Sort by
0
Pechka
Top achievements
Rank 1
answered on 29 Jun 2012, 07:02 AM
Hi,

What kind of binding do you use? 
0
AkAlan
Top achievements
Rank 2
answered on 29 Jun 2012, 03:11 PM

I'm using Ajax binding. Here is the code within my View:

.DataSource(dataSource => dataSource
                       .Ajax()
                       .Model(model => model.Id(p => p.ID))
                       .Batch(true)
                       .ServerOperation(false)
                       .Read(read => read.Action("Editing_Read", "Shipping"))
                       .Update(update => update.Action("Editing_Update", "Shipping"))
                       .Destroy(update => update.Action("Editing_Destroy", "Shipping"))
                   )
1
Pechka
Top achievements
Rank 1
answered on 02 Jul 2012, 11:22 AM
Hi,

Currently I you can achieve this easily with a template columns. Here is a similar scenario like this:

.Columns(columns =>
{
    columns.Bound(c => c.SomeVal);
    columns.Bound(c => c.Name).ClientTemplate("#= getFormat(SomeVal,Name)#");
})

and the following function which will handle the formatting:

function getFormat (val,name) {
        if (val> 10) {
            return name;
        }
        else {
            return "<div style='background:red'> "+ name +" </div>"
        }
    }

Tags
Grid
Asked by
AkAlan
Top achievements
Rank 2
Answers by
Pechka
Top achievements
Rank 1
AkAlan
Top achievements
Rank 2
Share this question
or