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

[Solved] Replace "Delete" and "Edit" commands

5 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
paulo larini
Top achievements
Rank 1
paulo larini asked on 25 Jul 2011, 11:37 AM
Hi, I don't want to use the default commands supplied by grid.
I want to write custom templates to exactly the same things.

How can I do this?



5 Answers, 1 is accepted

Sort by
0
william
Top achievements
Rank 1
answered on 25 Jul 2011, 12:00 PM
you should be able to use something like this: in general they work, but I am currently having a problem on 1 form that is hosted in a telerik tab.:
                                
    columns.Template(@<text>
                   @Html.ActionLink(" ", "Edit", "PolicyZone", new { policyZoneID = @item.Id }, new { @class = "editLink" })
                   @Html.ActionLink(" ", "Delete", "PolicyZone", new { policyZoneID = @item.Id, policyId = @item.PolicyId, policyVersion = @item.Version }, new { @class = "deleteLink" })
                   </text>).Width(20).Title("Commands");
    the classes are:

<script type="text/javascript">
    $(".editLink").button({ icons: { primary: "ui-icon-pencil"} }).height(18).width(24);
    $(".deleteLink").button({ icons: { primary: "ui-icon-trash"} }).height(18).width(24);
 </script>
0
paulo larini
Top achievements
Rank 1
answered on 25 Jul 2011, 12:39 PM
This works, but I´m trying to do this using Ajax, and the grid does not update after delete. Here is my code:

@model  Benner.Saude.Mapeamento.SamEspecialidade[]
 
@(Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(c => c.Handle))        
        .DataBinding(dataBinding => dataBinding
            .Ajax()
            .Select("AjaxPesquisar", "Especialidade")
            .Update("AjaxAtualizar", "Especialidade")
            .Delete("AjaxDelete", "Especialidade"))
        .HtmlAttributes(new { @class = "grid-padrao" })
        .ClientEvents(events => events
            .OnDataBound("atualizarCss")
        )
        .Columns(columns =>
        {
            columns.Template(@<text>
                   @Html.ActionLink(" ", "AjaxDelete", "Especialidade", new { id = @item.Handle }, new { @class = "formatacao delete-link", @image = "delete" })
                   </text>).Width(20).Title("Commands");
     
            columns.Bound("Descricao").Title("Descrição");
            columns.Bound("Handle").Title("Código");
 
        })       
        .Pageable()
        .Sortable()
         
        )



And javascript:
$("a.delete-link").click(function (event) {
    var link = $(this)[0];
 
    if (confirm("Confirma a exclusão do registro?")) {
        $.post(link.href);
        return false;
    }
});


and controller:
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
[GridAction]
public ActionResult Delete(int id)
{
    cadastro.ExcluirEspecialidade(Session["token"].ToString(), id);
    SamEspecialidade[] especialidades = consulta.PesquisarEspecialidades(Session["token"].ToString());
    return View(new GridModel(especialidades));
}
0
william
Top achievements
Rank 1
answered on 25 Jul 2011, 01:22 PM
try adding this to your data binding (note only available from the latest Telerik contols).

.OperationMode(GridOperationMode.Client)
0
paulo larini
Top achievements
Rank 1
answered on 25 Jul 2011, 03:14 PM
Tried, but does not works.

I just don't want to use default grid commands, because I think that this is not the way to do things.
I want to create my commands, I want to use many ones I want..

Can anyone please help me ?

0
paulo larini
Top achievements
Rank 1
answered on 26 Jul 2011, 02:07 PM
Problem solved with stack overflow guys help:

Change the javascript part to include a call to grid.rebind:

$("a.delete-link").click(function (event) {
    var link = $(this)[0];
  
    if (confirm("Confirma a exclusão do registro?")) {
        $.post(link.href, function(){
           var $grid = $("#Grid").data("tGrid");
             $grid.rebind();
         });
        return false;
    }
});
Tags
Grid
Asked by
paulo larini
Top achievements
Rank 1
Answers by
william
Top achievements
Rank 1
paulo larini
Top achievements
Rank 1
Share this question
or