This is a migrated thread and some comments may be shown as answers.

If-statement on command.Destroy()

9 Answers 447 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 01 Feb 2013, 10:35 AM
Hi,
I need to check the current item to display Destroy button or not. But I can't figure out how to write the if-statement.
Currently it looks like:
columns.Command(commands =>
{                
     commands.Edit();
     @<text>
     @if (!item.IsStartPage)
     {
          commands.Destroy();
     }
     </text>;
})

How should it look like?

And as I wrote in this thread: http://www.kendoui.com/forums/mvc/grid/enable-properties-by-true-false.aspx
it would be more beautiful to just write:
columns.Command(commands =>
{               
     commands.Edit();
     commands.Destroy(!item.IsStartPage);
})
:)

Regards,
Mattias

9 Answers, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 04 Feb 2013, 05:10 PM
Hello Mattias,

You could use the following syntax:

.Columns(columns =>
{
    columns.Command(c => c.Edit());
    if (!item.IsStartPage)
    {
        columns.Command(c => c.Destroy());
    }
})
  Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mattias
Top achievements
Rank 1
answered on 05 Feb 2013, 01:06 PM
Hi,
It doesn't seems to work. I'm getting: The name 'item' does not exist in the current context.
And I would like to have the 2 buttons in the same column as it is without if-statement, even if it's not the end of the world!

/Mattias

0
Dimiter Madjarov
Telerik team
answered on 05 Feb 2013, 03:52 PM
Hello Mattias,

To have the command buttons in the same column, you could use the following syntax:
.Columns(columns =>
{
    columns.Command(command =>
    {
        command.Edit();
        if (<custom condition>)
        {
            command.Destroy();
        }
    });
})

I am not sure what the item object is in your real scenario, but it is not related to the syntax for the condition statement. In my previous answer I simply used the condition that you used in the initial post.

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mattias
Top achievements
Rank 1
answered on 06 Feb 2013, 07:28 AM
For what I know "item" can be used to grab values in the grids datasource so "item" is not one of my own properties.
This is working but it's not pretty:
columns.Command(commands =>
{                
     commands.Edit();
});
                 
columns.Template(
   @<text>
         @{
            if(!item.IsStartPage)
            {
                <form action="/admin/menu/Delete/@item.ID" class="k-grid-actions" method="post">
                     <button class="k-button k-button-icontext k-grid-delete" type="submit"><span class="k-icon k-delete"></span>Radera</button>
                </form>
             }
          }
 </text>);
0
Dimiter Madjarov
Telerik team
answered on 06 Feb 2013, 02:09 PM
Hello Mattias,

You could use the RowAction method of the grid to attach a custom CSS class and hide the Delete button according to a specified condition.
E.g.

.RowAction(row =>
{
    if (row.DataItem.EmployeeID % 2 == 0)
    {
        row.HtmlAttributes["class"] = "hiddenDestroy";
    }
})

<style>
  .hiddenDestroy .k-grid-delete
  {
      display:none;
  }
</style>

Using the DataItem property you could get the properties, that are bound to the current row. I hope this will help you to maintain a cleaner grid declaration.

Regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mattias
Top achievements
Rank 1
answered on 07 Feb 2013, 08:47 AM
Hi,
No I don't think that is a cleaner solution. Do you really think so?
If missing to set the style in css file or if it's change in the future the button will be visible again.
Do you think it's a bad idea to be able to set it with a parameter or is it not possible (I know it's not implemented today, but in a future release)? Like:
command.Destroy(enabled=true/false);
or just add:
command.Destroy().Enabled(true/false);

Regards,
Mattias
0
Dimiter Madjarov
Telerik team
answered on 07 Feb 2013, 09:19 AM
Hi Mattias,

 
I could suggest you to submit this idea as a future request in Kendo UserVoice portal. If it gets enough votes from the community, we will consider to implement it in our future releases. 

Have a great day!

Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Mattias
Top achievements
Rank 1
answered on 07 Feb 2013, 09:44 AM
Yes, I can submit it there.
But if it don't get enough votes you will not implement it?
I wonder, how many users goes to the uservoice portal and votes?! And for what I saw, you only have a fixed number of votes to use.
Don't you upgrade your components even if it's not voted for?

I can't remember now but I wouldn't be surprised if the old Telerik Mvc grid had this feature! :/

Thank you for your time anyway! :)

/Mattias
0
Dimiter Madjarov
Telerik team
answered on 11 Feb 2013, 02:23 PM
Hi Mattias,

As you probably know we regularly add user driven features to Kendo UI development plan along with those that are already on the road map. The decision whether а feature will get implemented or not depends not only on it's necessity, but also on the requests and votes of the users.

Regarding your specific case, a syntax like this is not available neither in Kendo UI Grid nor in Telerik Grid. This is the first time we are receiving such inquiry and that is why I suggested you to submit it in Kendo user voice portal so other users could evaluate and vote for it. If this feature becomes popular with the users, we will consider adding it in a future release.

 
Greetings,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Mattias
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Mattias
Top achievements
Rank 1
Share this question
or