Skip to content

Infragistics Community Forum / Web / Ignite UI for jQuery / igGrid depending on value show value or image in grid

igGrid depending on value show value or image in grid

New Discussion
Ronny Gilisen
Ronny Gilisen asked on Jan 21, 2020 5:04 PM

I'm using an igGrid table for displaying my data in ASP.NET MVC (with razor views). I have a column "Category". Depending on if the value (type string) is empty or not I want to show eighter the value or an icon. How can I do this?

Currently I'm filling my array for the datasource like this:

<text>

vendorDetails.push(

{

"Id": @detail.Id,
"Vendor": "@(detail.Vendor)",
"Category": "@(detail.CategoryName?.Substring(0, 6))",
"PurVal": "@Math.Round(detail.PurchasedValue, 0)",
"Tot": "@totalP",
"TotSc": "@Math.Round(detail.TotSc, 2)",
"MaxSc": "@Math.Round(detail.MaxTotSc, 2)",
"ToScDel": "@Math.Round(detail.ToScDel, 2)",
"MaxScDel": "@detail.MaxScDel",
"TotScQua": "@Math.Round(detail.TotScQua, 2)",
"MaxScQua": "@detail.MaxScQua",
"TotScPurch": "@Math.Round(detail.TotScPurch, 2)",
"MaxScPurch": "@detail.MaxScPurch",
"AvgScoreDATE": "@Math.Round(detail.AvgScoreDATE, 2)",
"AvgScoreQTY": "@Math.Round(detail.AvgScoreQTY, 2)",
"PPM": "@Math.Round(detail.PPM, 0)",
"ReactivityScore": "@detail.Reactivity_Score",
"QltyTblCertificatesScore": "@detail.Qlty_TblCertificates_Score",
"InternalStopScore": "@detail.InternalStopScore",
"CustomerStopScore": "@detail.CustomerStopScore",
"SqAgreementScore": "@detail.SqAgreementScore",
"PriceScore": "@detail.PriceScore",
"QltyTblSupplierPaymenttermsScoreScore": "@detail.Qlty_TblSupplierPaymenttermsScore_Score",
"BackgroundColor": "@backgroundColor"

}

);

</text>

Sign In to post a reply

Replies

  • 0
    Vasya Kacheshmarova
    Vasya Kacheshmarova answered on Jul 1, 2019 12:58 PM

    Hello Ronny,

    Thank you for posting in our community.

    What I can suggest for achieving your requirement is using template column option. It gives you the opportunity to add conditional templates and style the cell based on your requirement. We have a working sample illustrating my suggestion here. In this sample  we set a template for Unit Price column. Depending on the Delta Price column value we render up or down arrow next to the cell value. The template looks like the following:

     
    

    This template is afterwards set to the template column option as following:

    { headerText: headerTextValues[1], key: "UnitPrice", type: 'number', width: 150, template: $( "#colTmpl" ).html() },

    In your scenario the template can be set in the Razor definition of the grid since the Template option takes string parameter. For example:

     .Columns(column =>
                    {
                        column.For(x => x.ProductName).HeaderText("Product Name").Width("30%");
                        column.For(x => x.CategoryName).HeaderText("Category").Width("30%");
                        column.For(x => x.UnitPrice).HeaderText("Unit Price").Width("20%").Template(" {{if parseInt(${UnitPrice}) >= 3 }} $ ${UnitPrice} {{else}}{{/if}}");
                        column.For(x => x.UnitsInStock).HeaderText("Units In Stock").Width("20%");
                    })

    The template from the code snippet above checks the of the Unite Price column`s value and if it is less than 3 only an arrow down is rendered, in case that the value is greater than 3 the value and error up is rendered in the cell.

    Some topic that I believe you might find helpful are available here and here.

    Please test this approach on my your side and let me know whether it helps you achieve your requirement.

    • 0
      Ronny Gilisen
      Ronny Gilisen answered on Jul 1, 2019 2:36 PM

      Thank you! This helped!

      • 0
        Vasya Kacheshmarova
        Vasya Kacheshmarova answered on Jul 2, 2019 6:54 AM

        Hello Ronny,

        I am glad that you find my suggestion helpful.

        Thank you for using Infragistics components.

    • 0
      Caty
      Caty answered on Jan 21, 2020 5:04 PM

      What if the value we want to check isn't in the list of columns? Using the example from the code examples provided, if there was another value called Discount, that isn't mapped to a column, but I wanted to use it in the template. Is that possible? Would it be possible on a Multi-row layout grid as well?

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Ronny Gilisen
Favorites
0
Replies
4
Created On
Jan 21, 2020
Last Post
6 years, 7 months ago

Suggested Discussions

Created by

Created on

Jan 21, 2020 5:04 PM

Last activity on

Jan 21, 2020 5:04 PM