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

[Solved] CellAction and incell editing

1 Answer 93 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.
hugues viens
Top achievements
Rank 1
hugues viens asked on 13 Dec 2011, 06:24 AM
Hi,

We are using the telerik components in our application and we are very satisfy with the product.
Regarding the telerik grid, we use the CellAction to customize the display value of a cell.
However, when the cell is edited using Incell Editing, after the validation, the grid returns to the default display, loosing the custom format applied by the CellAction.

Html.Telerik()
        .Grid((IEnumerable<Asclepios.Models.Element>)ViewBag.Element)
        .Name("gridElement")
        .HtmlAttributes(new { style = "outline: none;" })
        .Columns(cols =>
        {
            cols.Bound(c => c.Nom).ReadOnly();
            cols.Bound(c => c.Valeur);
            cols.Bound(c => c.Unite);
            cols.Bound(c => c.Note);
        })
        .DataKeys(d => d.Add(e => e.IdElement))
         .CellAction(cell =>
         {
             if ((cell.Column.Title == "Valeur"))
             {
                 if (cell.DataItem.idTyp != null)
                 {
                     //case a cocher
                     if ((cell.DataItem.idTyp.Trim() ?? "0") == "1")
                     {
                         String Check = cell.DataItem.Valeur.Trim() == "1" ? "checked=\"true\"" : "";
                         cell.Text = "<input type=\"checkbox\" disabled=\"disabled\" " + Check + "\">";
                     }
                     //date
                     if ((cell.DataItem.idTyp.Trim() ?? "0") == "4" || (cell.DataItem.idTyp.Trim() ?? "0") == "5")
                     {
                         cell.Text = (String.IsNullOrEmpty(cell.DataItem.Valeur)) ? "" : String.Format("{0:d}", DateTime.Parse(cell.DataItem.Valeur));
                     }
                 }
             }
         })
        .ToolBar(cmds =>
        {
            cmds.SubmitChanges().ButtonType(GridButtonType.Image);
        })
        .DataBinding(bind =>
            bind.Ajax()
                .Select("_SelectEvenementElement", "Evenement", new { id = Model.IDEVENEMENT.Trim() })
                .Update("_SaveEvenementElement", "Evenement", new { id = Model.IDEVENEMENT.Trim() })
        )
        .Editable(editing => editing.Mode(GridEditMode.InCell).Enabled(ViewBag.canEdit))
        .ClientEvents(events =>
                    events.OnEdit("Grid_onEdit")
 
                    )
        .KeyboardNavigation()
        .Footer(false)
        .Render();


Additional Information :telerik V.2011.3.1115.340
Application mvc 3

1 Answer, 1 is accepted

Sort by
0
hugues viens
Top achievements
Rank 1
answered on 14 Dec 2011, 06:57 AM
ha well, I found the solution. I had to use the OnGridSave to overload the default output.

ClientEvents(events =>
                    events.OnEdit("Grid_onEdit")
                    .OnSave("Grid_onSave")
                    )

and the Grid_onSave :

function Grid_onSave(e) {
       var dataItem = e.dataItem;
       var values = e.values;
       if ($.trim(dataItem.idTyp) == "4") {
                 values.Valeur = dateFormat(values.Valeur, "dd/mm/yyyy");
       }
   }
Tags
Grid
Asked by
hugues viens
Top achievements
Rank 1
Answers by
hugues viens
Top achievements
Rank 1
Share this question
or