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

Telerik Grid UI MVC - data disappears after load

4 Answers 578 Views
Grid
This is a migrated thread and some comments may be shown as answers.
kirtan
Top achievements
Rank 1
kirtan asked on 05 May 2016, 03:49 PM

Hello, I am using Kendo Grid on my MVC site. Loading data using AJAX call. But, the data disappears right after loading. Below is a code for Grid control in the view. 

@(Html.Kendo().Grid<SomeViewModelClass>()
            .Name("criteriaGridDiv")
            .AutoBind(false)
            .DataSource(datasource => datasource
                .Ajax()
                .Model(module =>
                    {
                        module.Id("ID");
                        module.Field("ScoreValue", typeof(int));
                        module.Field("ProjectID", typeof(string));
                        module.Field("CallMonitoringFormTypeID", typeof(int));
                        module.Field("FailureOnNotMet", typeof(bool));
                    })
               .Create(create => create.Action("Create_Criteria", "Permission", new { ModuleId = ViewBag.ModuleId }))
               .Update(update => update.Action("Edit_Criteria", "Permission", new { ModuleId = ViewBag.ModuleId }))
            )
            .Columns(columns =>
            {
                columns.Bound("ID").Visible(false);
                columns.Bound("ProjectID").Visible(false);
                columns.Bound("CallMonitoringFormTypeID").Visible(false);
                columns.Bound("CriteriaStatement").Title("Criteria");
                columns.Bound("ScoreValue").Title("Score Value").HtmlAttributes(new { style = "max-width:100px;" });
                columns.Bound("FailureOnNotMet").Title("Fail call if Not Met?").ClientTemplate("<input type='checkbox' #= FailureOnNotMet ? checked='checked':'' # class='failureOnNotMetCheck' />");
                columns.Command(command => command.Edit()).HtmlAttributes(new { style = "max-width:200px;" });
            })
            .ToolBar(toolbar => toolbar.Create().Text("Add New Criteria").HtmlAttributes(new { id = "radGridButton" }))
            .Editable(editable => { editable.Mode(GridEditMode.InLine); })            
            .HtmlAttributes(new { style = "max-width:90%;height:500px;" }))

Any thought on what I am missing here?

 

Thanks in advance. 

Kirtan

4 Answers, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 09 May 2016, 07:46 AM
Hello Kirtan,

From the provided code snippet I saw that you do not have a read method of the data source, there are only create and update method. When the grid needs to fetch a data it do it via read method.
http://docs.telerik.com/kendo-ui/aspnet-mvc/helpers/grid/binding/ajax-binding

Additionally in the provided code snippet where is a .AutoBind(false) setting. In this case the grid will not hit the server side read method until datasource read() method is not called manually. More information you can find here:
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#configuration-autoBind

So in your case you need to add an Read method and to set the AutoBind to true (or remove it as a setting because its default value is true).

I hope this helps.

Regards,
Radoslav
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Swati
Top achievements
Rank 1
answered on 26 Aug 2016, 05:17 AM

Hi Radoslav

I am facing the same issue. The grid data is disappearing sometimes and not always... The grid configuration is exactly the same as mentioned in this post i.e. AutoBind (false) and no read method in datasource.

Why this configuration ? - because I want to bind the grid only when it shows in a pop up window and not when the parent page loads.

If we configure the read method in design time then it would be called when the grid partial view renders on parent page load.

I understand that adding a read method to configuration will solve the issue. Is there a sure shot way where we don't bind the grid in configuration and bind it when ever we want via javascript?

0
Pavlina
Telerik team
answered on 29 Aug 2016, 09:58 PM
Hi,

To achieve your goal you should set the AutoBind to false, and then to populate the grid with data using the Read method when a certain event happens.

Regards,
Pavlina
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
kirtan
Top achievements
Rank 1
answered on 30 Aug 2016, 12:05 PM

Radoslav,

Thanks for the response.

Your solution worked for me. I put "Read" method with action call, and added AutoBind(false), so it won't load data when the parent page loads, but loads when the certain event is called.

 

Thanks again.

Tags
Grid
Asked by
kirtan
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Swati
Top achievements
Rank 1
Pavlina
Telerik team
kirtan
Top achievements
Rank 1
Share this question
or