If-statement on command.Destroy()

10 posts, 0 answers
  1. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 01 Feb 2013 Link to this post

    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
  2. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2286 posts

    Posted 04 Feb 2013 Link to this post

    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!
  3. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 05 Feb 2013 Link to this post

    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

  4. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2286 posts

    Posted 05 Feb 2013 Link to this post

    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!
  5. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 06 Feb 2013 Link to this post

    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>);
  6. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2286 posts

    Posted 06 Feb 2013 Link to this post

    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!
  7. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 07 Feb 2013 Link to this post

    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
  8. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2286 posts

    Posted 07 Feb 2013 Link to this post

    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!
  9. Mattias
    Mattias avatar
    263 posts
    Member since:
    Aug 2012

    Posted 07 Feb 2013 Link to this post

    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
  10. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2286 posts

    Posted 11 Feb 2013 Link to this post

    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!
Back to Top