Question

I am loading an Infragistics grid. When loading I have a template column that needs to inspect another value in the dataset before it knows what to load. It doesn't look like Infragistics will let me do this so I need to run a query on the grid after it is loaded to hide/show certain info.

For example:

My Grid:

            $("#divGrid").igGrid({
            columns: [
                {
                    headerText: "",
                    width: "70px",
                    key: "Division",
                    template: ProperRights.GetTemplate("${Division}")
                }
            ],
            primaryKey: "EmployeeNumber",
            autoGenerateColumns: false,
            dataSource: AccountAdministrationGrid.GetGridData()
        });

My js template logic:

    var ProperRights = new function () {
    this.GetTemplate = function(division) {
        if (division === 'DIV1') {
            return 'Special Stuff';
        } else {
            return "Boring Stuff";
        }
    };
};

That is what I would like to do, but the ProperRights.GetTemplate just returns ${Division} instead of the grid rows value.

So my next approach was to add a .ready() on the end of the grid. Then loop through each td and piece out the values from the row and change my values in the first column manually like so:

.ready(function () {
    $("td").each(function () {
        var id = $(this).text();
        console.log(id);
    });
});

But that does not work either, it keeps coming back as 0 td's found like the grid has not loaded yet.

Was it helpful?

Solution

In this case I suggest using Infragistics' templating engine in order to create a conditional template for your column. Some useful resources providing an overview of the Templating Engine and conditional row templates for the igGrid in particular may be found at:

http://help.infragistics.com/Help/NetAdvantage/jQuery/2012.2/CLR4.0/html/Creating_Conditional_Template_Containing_Default%20Statement.html

http://www.infragistics.com/products/jquery/sample/templating-engine/conditional-row-template

In your particular scenario, you can try something similar to:

        var ProperRightsTemplate = '{{if ${Division} == "Div1" }} <span> Some Value </span>';
        ProperRightsTemplate += '{{else}} <span> Some boring stuff </span> {{/if}}';

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top