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

deleting a row

16 Answers 764 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 15 Apr 2013, 12:38 PM
Hello,
i do not understand why the row is not deleted from the database.Actually is not getting on the server,to execute the delete action from the controller only on the client the row is removed .
i get an example from you guys,and i did the same

@(Html.Kendo().Grid<UCMSPayroll.ViewModels.TallyMeasurementViewModel>()
.Name("Grid")

.Columns(columns =>
{
columns.Template(x => { }).ClientTemplate(

 <a class='k-button' href='javascript: void(0)' onclick='deleteRow(this)' style='min-width:32px!important'><span class='k-icon k-delete'></span></a>"
).Width(100);

columns.Bound(p => p.Code).Title(Resources.Resources.FieldText_TM_Code);
columns.Bound(p => p.Name).Title(Resources.Resources.FieldText_TM_Name);
columns.Bound(p => p.MaxLength).Title(Resources.Resources.FieldText_TM_MaxLength).Width(130);
columns.Bound(p => p.IsActive).ClientTemplate("<input type='checkbox' disabled='true' name='IsActive' #= IsActive ? checked='checked' : '' # />").Title(Resources.Resources.FieldText_TM_IsActive);
columns.Bound(p => p.IsHour).ClientTemplate("<input type='checkbox' disabled='true' name='IsHour' #= IsHour ? checked='checked' : '' # />").Title(Resources.Resources.FieldText_TM_IsHour);
columns.Bound(p => p.Precision).Title(Resources.Resources.FieldText_TM_Precision);
columns.Bound(p => p.Priority).Title(Resources.Resources.FieldText_TM_Priority);
columns.Bound(p => p.Formula).Title(Resources.Resources.FieldText_TM_Formula);


})

.ToolBar(toolBar => toolBar.Template(@"<a class='k-button k-button-icontext k-grid-add' onclick='createRow()' href='javascript: void(0)'><span class='k-icon k-add'></span>adauga</a>
<span id='spanAdd' style='display:none'>Add</span>
<div style='float:right;width:150px;color:black;margin-top:5px'><b>Units</b></div>
"

))
.Pageable()
.Sortable()
.Scrollable()

.DataSource(dataSource => dataSource
.Ajax()
.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.PkTallyMeasurement))
.Create(update => update.Action("EditingInline_Create", "Home"))
.Read(read => read.Action("EditingInline_Read", "Home"))
.Update(update => update.Action("EditingInline_Update", "Home"))
.Destroy(update => update.Action("EditingInline_Destroy", "Home"))
.PageSize(6)

)
)

function deleteRow(element) {
 
grid = $("#Grid").data("kendoGrid");
grid.removeRow($(element).closest("tr"));
 }

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditingInline_Destroy([DataSourceRequest] DataSourceRequest request, TallyMeasurementViewModel measurement)
{
if (measurement != null)
{
_tallyMeasurementRepository.Delete(AutoMapper.Mapper.Map<TallyMeasurementViewModel, TallyMeasurement>(measurement));
}

return Json(ModelState.ToDataSourceResult());
}

16 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 16 Apr 2013, 03:34 PM
Hi Daniel,

 
From the provided information it seems that the current behavior is expected with the current grid configuration - the default edit mode is "InCell" in which you should press the "Save Changes" button in the grid toolbar to sync the changes with the server. In current setup however the "Save Changes" button is missing - you can add it using the following HTML:

<a class="k-button k-button-icontext k-grid-save-changes" href="javascript:void(0)">
    <span class="k-icon k-update"></span>Save changes
</a>
<a class="k-button k-button-icontext k-grid-cancel-changes" href="javascript:void(0)">
    <span class="k-icon k-cancel"></span>Cancel changes
</a>

 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!
0
Daniel
Top achievements
Rank 1
answered on 17 Apr 2013, 06:45 AM
I get an example from your coleg,regarding a custom image button,and there in the example was inline mode,for editing.
If i do not use any editing mode,but i still put actions on datasource(.Destroy,.Update,.Create,.Read) with the crud operations,it will go to the server and execute the actions or do i have to be in one of the 3 editing modes?

Regards,
Daniel
0
Vladimir Iliev
Telerik team
answered on 17 Apr 2013, 10:23 AM
Hi Daniel,

 
Basically if current grid configuration requires the grid to be editable it automatically sets the edit mode to "InCell" mode. If you need another edit mode you should define it explicitly.

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!
0
Daniel
Top achievements
Rank 1
answered on 18 Apr 2013, 02:45 PM
so i need to use ajax to call my delete operation .
for example at this post,
http://www.kendoui.com/forums/mvc/grid/customize-add-delete-edit-buttons.aspx
your colegue sent me an example with custom buttons,there should be also be able to delete from database with the custom image buttons.in that case you delete from database?

Regards,
Daniel

0
Vladimir Iliev
Telerik team
answered on 19 Apr 2013, 05:34 AM
Hi Daniel,

 
In the example that you pointed the delete button calls the destroy action directly to delete the record on the server ("InLine" / "PopUp" edit modes). The "InCell" edit mode allows the user to batch edit the grid records and sync the changes with the server once the "Save Changes" command is clicked.

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!
0
Daniel
Top achievements
Rank 1
answered on 19 Apr 2013, 09:29 AM
ok,so for my custom buttons,if there is no editmode present on the grid,i have to handle myself the delete/edit operations?

Regards,
Daniel
0
Vladimir Iliev
Telerik team
answered on 23 Apr 2013, 08:49 AM
Hi Daniel,

 
The Grid attaches click event handler to all elements with CSS classes "k-grid-save-changes" and "k-grid-cancel-changes" which calls the cancelChanges and saveChanges methods. In current scenario when edit mode in not defined and the grid data is edited the grid will use the default edit mode ("InCell").

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!
0
Daniel
Top achievements
Rank 1
answered on 24 Apr 2013, 07:15 AM
how can be in-cell,if i cannot modify any value in the grid?also i didn't put the batch command for the grid,so it seems to me that it's only a read-only grid.

until now,i managed to do manually the operations,because i do not want to make a batch edit,nor to put a save/cancel button on top.the grid only show read-only data,and when i press  delete custom button,to make the action on the server after of course a confirmation.for the edit,i show an edit form with the data from the clicked row,and only then if i press a save button,to make the update with the modified row.
0
Vladimir Iliev
Telerik team
answered on 25 Apr 2013, 02:17 PM
Hi Daniel,

 
Thank you for the last clarification - for convenience I created small demo of grid without edit mode set (and delete button which sends the deleted record immediately to the server) and attached it to the current thread. Could you please check it and let me know how it differs from your real setup?

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!
0
Daniel
Top achievements
Rank 1
answered on 25 Apr 2013, 02:44 PM
the ideea is that,indeed it goes on server,but regarding the functionality the example is not functional,because the order passed in the delete action doesn't contain the data for the selected order to be deleted,everything is null or 0 .the entity is removed only on client-side from the grid,not via server from a database,or at least from that colection that you have made.

Regards,
Daniel
0
Accepted
Vladimir Iliev
Telerik team
answered on 26 Apr 2013, 05:33 AM
Hi Daniel,

 
Please find attached the updated project.

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!
0
Daniel
Top achievements
Rank 1
answered on 26 Apr 2013, 06:57 AM
now it looks ok the project,and has custom buttons,and does something on server,thank you.

But i keep see in that template
columns.Template(t => { }).HeaderTemplate("").ClientTemplate(@"
<a href='javascript: void(0)' class='abutton edit' onclick='editRow(this)' title='button edit'>button edit</a>
<a href='javascript: void(0)' class='abutton delete' onclick='deleteRow(this)' title='button delete'>button delete</a>")

if i have to give other parameters to that editRow javascript function,for example a string something like editRow('text') can i do it and how do i format this in that template context?

Regards,
Daniel
0
Vladimir Iliev
Telerik team
answered on 30 Apr 2013, 06:57 AM
Hi Daniel,


The last second question is not related to the original topic of this support conversation, so please submit a new support ticket / forum post for it. In this way you can be sure that your query will reach the corresponding staff member in time and will be answered faster and accurately.

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!
0
Neha
Top achievements
Rank 1
Veteran
answered on 10 Aug 2020, 09:41 AM
Hey, I download this project but cannot get the desired output. The delete is being done on the client side only & the controller method for delete is not called. No delete on the database sie
0
Neha
Top achievements
Rank 1
Veteran
answered on 10 Aug 2020, 09:42 AM
Hey, I download this project but cannot get the desired output. The delete is being done on the client side only & the controller method for delete is not called. No delete on the database side
0
Petar
Telerik team
answered on 12 Aug 2020, 06:31 AM

Hi Neha,

I've just tested the provided by Vladimir project and it is working as expected on my end. The Delete controller method is called when a deletion is confirmed.

To be able to help you, I will need a runnable project in which the reported behavior can be replicated. Can you send me such an example?  

Regards,
Petar
Progress Telerik

Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Daniel
Top achievements
Rank 1
Neha
Top achievements
Rank 1
Veteran
Petar
Telerik team
Share this question
or