Grid - Allow only Insert and delete inline edit (Version 2023.2.718)

1 Answer 86 Views
Grid
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 01 Sep 2023, 10:20 AM

I have a sub grid which contains a single foreign key column. As such, it doesn't make sense for this grid to allow edits, just deletes and inserts. However, if I remove the edit command, the cancel button is no longer visible.

I have tried the suggestion in the post here Grid: Insert and Delete only, no update of existing records in UI for ASP.NET MVC | Telerik Forums however this does not seem to work.

I am using version v2023.2.718.

How can I remove the edit button, but keep the cancel button for inserts when using inline editing?

My grid definition is:-


<script id="subdetailsTemplate" type="text/kendo-tmpl"> @(Html.Kendo().Grid< KPIDataEntryForms.Models.IndicatorBundlesToMetricsMap> () .Name("mapGrid_#=ID#") .Columns(col => { col.Bound(o => o.ID).Title("ID").Width(150); //col.Bound(o => o.IndicatorBundle).Title("Bundle ID"); //col.Bound(o => o.MetricID).Title("Metric ID"); col.ForeignKey(p => p.MetricID, ds => ds.Read(r => r.Action("GetMetrics", "ScoreCards")), "MetricID", "MetricName") .Title("Metric").Width(500); col.Command(command => { command.Destroy().Text(" "); command.Edit().Text(" ").UpdateText(" ").CancelText(" "); }); }) .ToolBar(tb => tb.Create()) .Editable(e => e.Mode(GridEditMode.InLine)) .Events(e=>e.DataBound("hideUpdateBtn")) .DataSource(ds => ds .Ajax() .Events(e => e.Error(o => gridTemplateHelper("#=ID#"))) .Model(m => { m.Id(p => p.ID); m.Field(p => p.ID).Editable(false); }) .PageSize(15) .Read(rd => rd.Action("RD_BundleMaps", "ScoreCards", new { BunID = "#= ID #" })) .Create(u => u.Action("InsertBundleMap", "ScoreCards", new { BunID = "#= ID #" })) .Destroy(u => u.Action("DeleteBundleMap", "ScoreCards")) .Update(u => u.Action("DeleteBundleMap", "ScoreCards")) .Sort(s => { s.Add(a => a.ID).Descending(); }) ) .Pageable(p=>p.Refresh(true)) .Sortable() .ToClientTemplate() ) </script>

And
		<script type="text/javascript">
		
    function hideUpdateBtn()
    {
            this.table.find(".k-grid-edit").hide();
        }
    

</script>


-

AP
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 01 Sep 2023, 03:19 PM

After further investigation i changed the function to:-


 function hideUpdateBtn()
    {
       
            this.table.find(".k-grid-edit-command").hide();
        }
This seems to work - is it the best way to do this?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 06 Sep 2023, 05:17 AM

Hi Andrew,

Hiding the buttons in the DataBound event handler is one way to do it. The other way is to use the Edit command's Visible option to hide it.

The Visible option accepts a function:

command.Edit().Visible("visibleHandler");
The function:

function visibleHandler(e) {
    return false
}

Here's an example showing how it works: https://netcorerepl.telerik.com/cxOXEgEf14veCEkT13

Regards,
Ivan Danchev
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.

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