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

4 posts, 0 answers
  1. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 28 Jun 2012 Link to this post

    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.
  2. Pechka
    Pechka avatar
    56 posts
    Member since:
    May 2010

    Posted 29 Jun 2012 Link to this post

    Hi,

    What kind of binding do you use? 
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. AkAlan
    AkAlan avatar
    121 posts
    Member since:
    Jun 2009

    Posted 29 Jun 2012 Link to this post

    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"))
                       )
  5. Pechka
    Pechka avatar
    56 posts
    Member since:
    May 2010

    Posted 02 Jul 2012 Link to this post

    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>"
            }
        }

Back to Top
UI for ASP.NET MVC is VS 2017 Ready