[CLOSED] Conditional Hyperlink in the Grid

  1. #1

    [CLOSED] Conditional Hyperlink in the Grid

    Hi,
    I have a grid defined as follows -

    @(X.GridPanel()
        .ID("GridPanel1")
        .Width(400)
        .Store(X.Store()
            .Model(X.Model()
                .Fields("someName", "someId","status")
            )
            .DataSource(Model)
        )
        .ColumnModel(
            X.Column().Text("Some Name").DataIndex("someName"),
            X.Column().Text("Some ID").DataIndex("someId"),
            X.HyperlinkColumn()
                .ID("HyperlinkColumn1")
                .Text("Status")
                .Width(150)
                .DataIndex("someName")
                .DataIndexHref("someId")
                .HrefPattern("http://someurl?someId={href}")
        )
    )
    My requirements is, to show the link only if the status='APPROVED', else display the Status column (in the above grid definition) as plane text. Can you please give some clue, how it can be achieved ?

    Thanks
    Last edited by Daniil; Sep 15, 2015 at 7:55 PM. Reason: [CLOSED]
  2. #2
    Hi @barnali,

    I would implement it like this.

    Example

    @{
        var X = Html.X();
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v3 Example</title>
    
        <script>
            var statusRenderer = function (value, metadata, record) {
                var me = this,
                    data = {
                        text: value,
                        href: record.data[me.dataIndexHref]
                    };
    
                if (!me.patternTpl) {
                    me.updatePatternTpl();
                }
    
                if (record.data.status === "Approved") {
                    value = me.patternTpl.apply(data);
                }
    
                return value;
            };
        </script>
    </head>
    <body>
        @X.ResourceManager()
    
        @(X.GridPanel()
            .Width(400)
            .Store(X.Store()
                .Model(X.Model()
                    .Fields("someName", "someId", "status")
                )
                .DataSource(new object[]
                {
                    new
                    {
                        someName = "Some name 1",
                        someId = "Some id 1",
                        status = "Approved"    
                    },
                
                    new
                    {
                        someName = "Some mame 2",
                        someId = "Some id 2",
                        status = "Not approved"    
                    }
                })
            )
            .ColumnModel(
                X.Column().Text("Some Name").DataIndex("someName"),
                
                X.Column().Text("Some ID").DataIndex("someId"),
                
                X.HyperlinkColumn()
                    .Text("Status")
                    .DataIndex("someName")
                    .DataIndexHref("someId")
                    .HrefPattern("http://someurl?someId={href}")
                    .Renderer("statusRenderer")
                    .PreInit(new JFunction("this.scope = this;")) // That is required to have "this" being a Column in a Renderer function
            )
        )
    </body>
    </html>

Similar Threads

  1. Replies: 3
    Last Post: Feb 02, 2015, 5:32 AM
  2. how to set a hyperlink for a row in a grid panel
    By Chaitanya in forum 2.x Help
    Replies: 2
    Last Post: Jan 07, 2015, 7:17 PM
  3. Grid panel conditional validation
    By Argenta in forum 2.x Help
    Replies: 2
    Last Post: Dec 17, 2014, 8:00 AM
  4. [CLOSED] Grid Panel - Conditional Editing
    By adelaney in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Sep 17, 2012, 6:03 AM
  5. Replies: 6
    Last Post: Feb 22, 2012, 5:43 PM

Posting Permissions