Hide edit and delete button based on the status of each record.

13 posts, 0 answers
  1. Mu
    Mu avatar
    1 posts
    Member since:
    Jun 2012

    Posted 10 Oct 2012 Link to this post

    columns.Command(command => { command.Edit(); command.Destroy(); })
    


    How can I add condition to each record to hide or show these two button?

    If it is impossible, how could I handle the button by checking when user click edit button on each record.

    Thank you,
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 15 Oct 2012 Link to this post

    Hi Chanavath,

     
    Basically you should use the DataBound client event of the Grid to iterate over the Grid rows and check custom field in the model if the current row is editable and/or deletable. Such example can be:

    function onDataBound() {
        //Selects all edit buttons
        $("#Grid tbody tr .k-grid-edit").each(function () {
            var currentDataItem = $("#Grid").data("kendoGrid").dataItem($(this).closest("tr"));
     
            //Check in the current dataItem if the row is editable
            if (currentDataItem.isEditable == true) {
                $(this).remove();
            }
     
                 
        })
     
        //Selects all delete buttons
        $("#Grid tbody tr .k-grid-delete").each(function () {
            var currentDataItem = $("#Grid").data("kendoGrid").dataItem($(this).closest("tr"));
     
            //Check in the current dataItem if the row is deletable
            if (currentDataItem.isDeletable == true) {
                $(this).remove();
            }
        })
    }


    Kind Regards,
    Vladimir Iliev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Sodi We
    Sodi We avatar
    160 posts
    Member since:
    Apr 2010

    Posted 29 May 2013 Link to this post

    We have a grid where the editbuttons are always visible. The delete button is only visible when a certain
     property in the row is set to true.

    The code you gave work perfect untill we edited a row and clicked the cancel button. In this case the remove is
     visible again. I tried to call the code to remove the button on the Cancel event but this didn't work. I think
     because the cancel event is called to early to do this.

    Is there a way to solve this problem ?

    Thnx
    Sodi We
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 30 May 2013 Link to this post

    Hi Sodi,

     
    I already answered to this query in duplicated support ticket created by you - #698769. Please keep in mind that it is highly recommended that you keep related questions in one support thread or a forum post, so that we can easily keep track of your support history and provide better answers in a shorter time.

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Peter
    Peter avatar
    1 posts
    Member since:
    Jul 2013

    Posted 21 Aug 2013 Link to this post

    Any chance you could share this solution with the rest of us??
    I have the exact same problem. The delete button re-appears when the edit is cancelled.
  7. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 26 Aug 2013 Link to this post

    Hi Peter,

     
    Please check the answer below:

    I will suggest to use the Edit event of the Grid to attach click event handler to the "Cancel" button in which to manually trigger the DataBound event using setTimeout function.

    e.g.:

    function onEdit() {
        $(".k-grid-cancel").on("click", function () {
            setTimeout(function () {
                console.log("trigger");
                $("#Grid").data("kendoGrid").trigger("dataBound");
            });
        })
    }
    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  8. Gareth
    Gareth avatar
    5 posts
    Member since:
    Oct 2012

    Posted 18 Sep 2013 Link to this post

    I'm using the server wrappers for ASP.Net MVC.  I'd really like to be able to do something like:
    columns.Command(command => command.Destroy()).Width(90).DisplayWhen(p => p.isDeletable);  
    Is that possible?
    Thanks
  9. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 19 Sep 2013 Link to this post

    Hi Gareth,

     
    Currently this feature is not supported, however I would suggest to share your idea at KendoUI UserVoice to allow other users vote for it. Most voted ideas are included in next KendoUI releases. 

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  10. Daniel
    Daniel avatar
    17 posts
    Member since:
    Jan 2014

    Posted 20 Aug 2014 Link to this post

    Hi All,

    this would be a fantastic feature!
    "Conditional buttons" are a basic requirement in every business application.


    Regards,
    Daniel
  11. BN
    BN avatar
    2 posts
    Member since:
    Feb 2012

    Posted 16 Mar 2015 in reply to Daniel Link to this post

    Do you have this feature available now?
  12. BN
    BN avatar
    2 posts
    Member since:
    Feb 2012

    Posted 16 Mar 2015 in reply to Vladimir Iliev Link to this post

    Do you have this feature available now?  Let me know, very useful feature.
  13. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 17 Mar 2015 Link to this post

    Hello Prahlad,

    This feature is not yet available - for more information on the matter I would suggest to regularly check the UserVoice portal and Kendo UI RoadMap

    Regards,
    Vladimir Iliev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  14. Jeff
    Jeff avatar
    4 posts
    Member since:
    Feb 2012

    Posted 28 Jan Link to this post

    If anyone else sees this thread please visit this URL and vote for this feature to be implemented.

     http://kendoui-feedback.telerik.com/forums/127393-telerik-kendo-ui-feedback/suggestions/9411468-conditional-for-grid-columns-and-buttons

Back to Top
Kendo UI is VS 2017 Ready