Tazani
Tazani

Reputation: 39

IF with ClientDetailTemplateId

It is possible to add condition to linq in asp.net

@(Html.Kendo().Grid<>().
Name("myUniqName").
Columns(columns => {
  columns.Bound(p => p.Title).Width(100).Title("Mytitle");
  columns.Bound(p => p.Text).Width(250).Title("Txt").ClientTemplate("#=Text#");
}).
 if (number == 1){
   .ClientDetailTemplateId("gridSczegolyNazwa")
 }else{
   .ToClientTemplate() 
 }
)

Is it possible to add a condition as in the example above?

Upvotes: 1

Views: 1841

Answers (4)

MIDI
MIDI

Reputation: 21

You can use the following code on the dataBound event, to hide triangle :

function dataBound(e) {
    var items = e.sender.items();
    items.each(function () {
        var row = $(this);
        var dataItem = e.sender.dataItem(row);
        if (dataItem.number != 1) {
            row.find(".k-hierarchy-cell > a.k-icon.k-i-expand").css("visibility", "hidden");
        }
    })                   
}

With the above, we check the current 'number' of the master row, and based on its number the triangle is being hidden.

Upvotes: 0

Kobbe
Kobbe

Reputation: 845

I used an inline if inside the ClientDetailTemplateId and set the false option to "" and it worked for me.

.ClientDetailTemplateId(model.useDetailTemplate ? "gridSczegolyNazwa" : "")

Upvotes: 1

mohammad piri
mohammad piri

Reputation: 1

I found a way first set hierarchy column display to none :

.k-hierarchy-cell {
        display: none;
    }

then add a template column like this to create your hierarchy column conditionally :

columns.Template(@<text></text>).ClientTemplate(@"#if(hasHierarchy== true ) {#<a class='k-icon k-i-expand' href='\\#' aria-label='Expand' tabindex='-1'></a>#}#").HtmlAttributes(new { @class = "k-hierarchy-cell-active k-hierarchy-cell" });

at the end set this column display to block :

.k-hierarchy-cell-active {
        display: block;
    }

Upvotes: 0

dimodi
dimodi

Reputation: 4139

Unfortunately not, you will need two alternative Grid declarations and the IF statement should be on the outside.

Upvotes: 0

Related Questions