deleting a row

14 posts, 1 answers
  1. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 15 Apr 2013 Link to this post

    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());
    }
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 16 Apr 2013 Link to this post

    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!
  3. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 17 Apr 2013 Link to this post

    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
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 17 Apr 2013 Link to this post

    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!
  5. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 18 Apr 2013 Link to this post

    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

  6. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 19 Apr 2013 Link to this post

    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!
  7. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 19 Apr 2013 Link to this post

    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
  8. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 23 Apr 2013 Link to this post

    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!
  9. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 24 Apr 2013 Link to this post

    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.
  10. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 25 Apr 2013 Link to this post

    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!
  11. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 25 Apr 2013 Link to this post

    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
  12. Answer
    Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 26 Apr 2013 Link to this post

    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!
  13. Daniel
    Daniel avatar
    192 posts
    Member since:
    Mar 2012

    Posted 26 Apr 2013 Link to this post

    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
  14. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2194 posts

    Posted 30 Apr 2013 Link to this post

    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!
Back to Top