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

Conditionally Hide Create Button on Sub-Grid

2 Answers 539 Views
Grid
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 08 Jun 2016, 09:10 AM

I've got a sub-grid, which needs to allow records to be inserted, dependant on a value in the parent record.

I've got an onBound handler, which gets passed the subGrid name, but what do I need to do to hide the create button in the toolbar?

The toolbar is defined here:-

@(Html.Kendo().Grid<SystemsHelpDesk.Models.View_Support_Action>()
         .Name("ActionGrid_#=LogID#")
           .Events(e => e.Edit("onEdit"))
         .Columns(columns =>
         {
             columns.Bound(o => o.ActionID).Title("ID");
             columns.Bound(o => o.ActionDate).Title("Date").Format("{0:g}");
             columns.Bound(o => o.CategoryDescription).Title("Category");
             columns.Bound(o => o.ActionDesc).Title("Details");
             columns.Bound(o => o.UserName).Title("User");
 
         })
    .ToolBar(commands => commands.Create().Text("Add Action"))
 
 
 
  .Events(e => e.DataBound(@<text> function(e){onSubBound(e,"ActionGrid_#=LogID#",#=Resolved#)}</text>))
  .Editable(editable => editable
       .Mode(GridEditMode.PopUp))
 
         .DataSource(dataSource => dataSource
 
             .Ajax()
              .Events(e => e.Error(@<text> function(e){subError(e,"ActionGrid_#=LogID#")} </text>).Sync("ActionSync"))
              .Model(m => m.Id(p => p.ActionID))
             .PageSize(10)
                             .Read(read => read.Action("RD_Actions", "Home", new { LogID = "#= LogID #" }))
                               .Create(create => create.Action("InsertAction", "Home", new { LID = "#= LogID #" }))
                   .Update(update => update.Action("UpdateAction", "Home"))
                       .Destroy(delete => delete.Action("DeleteAction", "Home"))
             )
             .Pageable(p => p.Refresh(true))
 
             .ToClientTemplate()
 
   )

I can pass the Grid name and the value of the Boolean field that determines if records should be able to be added, but I'm at a loss at how to hide the button. I have tried:-

function onSubBound(e,gridName,Flag)
            {
               // alert(gridName);
                //alert(Flag);
 
                var grid = $(document.getElementById(gridName)).data("kendoGrid");
 
                $(grid).find("k-grid-toolbar").hide();
 
 
            }

But this doesn't work.

How can I hide the button when I need to?

Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Eyup
Telerik team
answered on 13 Jun 2016, 05:26 AM
Hi Andrew,

You can use the detailExpand event handler to achieve this requirement:
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-detailExpand

For example:
.Events(events=>events.DetailExpand("detailExpand"))
JavaScript:
function detailExpand(args) {
    var masterRow = this.dataItem(args.masterRow);
    var value = this.dataItem(args.masterRow).ProductName;
 
    if (value.indexOf("8") >= 0) {
        var detailGrid = args.detailRow.parents(".k-widget.k-grid");
        detailGrid.find(".k-grid-toolbar").hide();
    }
}

That should do the trick. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 20 Jun 2016, 08:24 AM

Sorry for the delay (I've been on leave), this works like a charm.

 

Thanks

Tags
Grid
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Eyup
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or