Kendo Grid Data store to session

1 Answer 383 Views
Grid
Shijo
Top achievements
Rank 1
Shijo asked on 27 Mar 2022, 01:49 PM | edited on 28 Mar 2022, 11:19 AM

@(Html.Kendo().Grid<TelerikMvcApp1.Models.EmpDependentViewModel>()
.Name("Dependentgrid")
.Columns(columns =>
{
    columns.Bound(c => c.serialNo).Visible(false);
    columns.ForeignKey(c => c.RelationCode, (System.Collections.IEnumerable)ViewData["relations"], "RelationCode", "Relation").Title("Dependent").Width(60);
    columns.Bound(c => c.FirstName).Width(50);
    columns.Bound(c => c.MiddleName).Width(50);
    columns.Bound(c => c.LastName).Width(50);
    columns.Bound(c => c.DateOfBirth).ClientTemplate("#=  (DateOfBirth == null)? '' : kendo.toString(kendo.parseDate(DateOfBirth, 'yyyy-MM-dd'), 'MM/dd/yy') #").Width(60);//("#= kendo.toString(DateOfBirth, \"MM/dd/yyyy\") #").Width(60);
    columns.Command(command => {command.Custom("Edit").Click("AddEvent"); command.Destroy(); }).Width(60);
    //columns.Command(command => command.Custom("select").Text("Select").Click("AddEvent")).Width(60);

})
.ToolBar(toolbar =>
{
    toolbar.Create();

})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Scrollable()

.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Events(events => events.Error("error_handler"))
.Read(read => read.Action("EmpDependent_Mst_Read", "Grid", new { id = Model.EmpCode }))
.Create(create => create.Action("EmpDependent_Mst_Create", "Grid", new { id = Model.EmpCode }))
.Update(update => update.Action("EmpDependent_Mst_Update", "Grid"))
.Destroy(destroy => destroy.Action("EmpDependent_Mst_Destroy", "Grid"))
.Model(model => model.Id(p => p.EmpCode))
)
)

 

 

Script

  function AddEvent() {
       
        var grid = $("#Dependentgrid").data("kendoGrid");
       
        var dataRows = grid.items();
       
        Session["DepenetGrid"] = dataRows;
    }

But my session is Empty 

 

Controller

 

  public ActionResult EmpDependent_Mst_Read([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")] IEnumerable<EmpDependentViewModel> empDependents, int id)
        {
        
            IQueryable<EmpDependent_Mst> empdependent_mst = db.EmpDependent_Mst;
            DataSourceResult result = null;
            if (Session["DepenetGrid"] == null)
            {
                result = empdependent_mst.Where(x => x.EmpCode == id).ToDataSourceResult(request, c => new EmpDependent_Mst
            {
                EmpCode = c.EmpCode,
                serialNo = c.serialNo,
                RelationCode = c.RelationCode,
                Lineage = c.Lineage,
                FirstName = c.FirstName,
                MiddleName = c.MiddleName,
                LastName = c.LastName,
                DateOfBirth = c.DateOfBirth,
              
            });
            }
            else
            {
                result = (DataSourceResult)Session["DepenetGrid"];
            }
            return Json(result);
        }

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 30 Mar 2022, 11:02 AM

Hi Shijo,

 

Thank you for writing to us.

I am afraid it is not possible to access the Server Session in javascript:

Session["DepenetGrid"] = dataRows;
You can use the window.sessionStorage provided by the browsers::
https://www.w3schools.com/html/html5_webstorage.asp

 

Regards,
Eyup
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Grid
Asked by
Shijo
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or