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

Conditionally display Destroy button?

5 Answers 287 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 20 Sep 2012, 05:35 AM
Hi,

Is it possible to conditionally display the destroy button? I've messed with command.Destroy().HtmlAttributes... but it is not working.

Thanks!
David A.

5 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 21 Sep 2012, 01:52 PM
Hello David,

You are trying to use an approach that is applicable only with server data binding. If you are using client-side binding, please hide the buttons with Javascript in the Grid's dataBound event handler.

All the best,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
David A.
Top achievements
Rank 1
answered on 21 Sep 2012, 08:20 PM
Hi Dimo,

Thanks for your response but I couldn't find any substantial documentation on the dataBound event.  Not sure if this is the best way to do it, but I ended up creating a template and it works fine.

David A.

c.Template(@<text></text>).ClientTemplate(@"
                    <a style=""margin-left: 5px;"" class=""k-button k-button-icontext k-grid-edit"" href=""\#""><span class=""k-icon k-edit""></span>Edit</a>
                    # if (TownshipsReceived==0) { #               
                    <a style=""margin-left: 5px;"" class=""k-button k-button-icontext k-grid-delete"" href=""\#""><span class=""k-icon k-delete""></span>Delete</a>
                    # } #").Width(180);
0
Daniel
Top achievements
Rank 2
answered on 01 Oct 2012, 12:16 PM
Hi,

I use the said method

Like:
function onDataBound(e) {
   var data = this._data;
   for (var x = 0; x < data.length; x++)
   {
      var dataItem = data[x];
      if (dataItem.HasMembers)
      {
         var tr = $("#Affiliate").find("[data-uid='" + dataItem.uid + "']");
         tr.find('a.k-grid-delete').remove();
      }
   }
}

the problem is that if I enter editmode and the cancel that edit the delete button reapperas.

Best Regards
Daniel

0
Dimo
Telerik team
answered on 02 Oct 2012, 07:59 AM
Hello Daniel,

Indeed, the delete button reappears, because the Grid is not aware of the customization that you have made. You can attach a click handler to the "Cancel" button in the Grid's edit event and remove the "Delete" button again by using setTimeout.

.Events(ev => ev.DataBound("onDataBound").Edit("attachRemove"))


function attachRemove(e) {
    var idx = e.container.index(),
        parent = e.container.parent();
    e.container.find(".k-grid-cancel").click(function() {
        window.setTimeout(function(){
            parent.children().eq(idx).find('a.k-grid-delete').remove();
        }, 1);
    });
}


Regards,
Dimo
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Daniel
Top achievements
Rank 2
answered on 03 Oct 2012, 08:33 AM
Thanks,

works perfectly, you saved my day.

Best Regards
Daniel
Tags
Grid
Asked by
David A.
Top achievements
Rank 1
Answers by
Dimo
Telerik team
David A.
Top achievements
Rank 1
Daniel
Top achievements
Rank 2
Share this question
or