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

Set column Command Visible

1 Answer 1663 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lorena
Top achievements
Rank 1
Lorena asked on 10 Jul 2018, 10:10 PM

I'm trying to set the destroy command visible. I need the button turn to visible or invisible using a condition(The condition depends on the selection from a DropDownList column). The first time that grid load the button shows perfectly, but when the grid changed the visible function doesn't work, the button do not turn to visible or invisible. 

Is there any way that I can accomplish that?  Thanks

This is my code:

columns.Command(command =>
 {
     command.Destroy().Visible("ButtonDestroyVisible");
});

function ButtonDestroyVisible(dataItem) {
    return dataItem.Status.StatusId == 1;       //Set to visible when StatusId == 1
}

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 12 Jul 2018, 10:18 AM
Hi Lorena,

The visible option will determine whether a command will be displayed when the Grid is rendered. Thus, when clicking Save Changes and the updated value is persisted to the server the destroy command will be hidden if necessary. 

If you would like to hide the destroy button as the user makes changes I would suggest using the save event. The handler would look similar to the following:


function onSave(e) {
  var row = e.container.closest("tr");
  var btn = row.find(".k-grid-delete");
 
  if (e.values.ProductName == "Chai") {
    btn.hide(); 
  }
}


I also prepared a small dojo illustrating the approach. The relevant logic when using MVC wrappers will be the same.



Give the approach a try and let me know how it works for you.

Regards,
Viktor Tachev
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Lorena
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or