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

Updating Grid's datasource

3 Answers 1102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KMILO
Top achievements
Rank 2
KMILO asked on 13 Jul 2012, 08:56 PM
well I must confess that im a little newbie using kendoui grid, I was trying to get data from REST service and put them on a globally var on js, so when the datasource change, I was trying to execute refresh method of grid just after I change manually the datasource and nothing happens, what im doing wrong?

here is my code attached

Any help will be appreciatted.

Thank you in advance

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 18 Jul 2012, 08:36 AM
Hello,

In order to change local DataSource's data you should use its data method passing the new data. This will automatically trigger DataSource change event and notify the associated widgets (in this case the Grid widget) to repaint themselves.

dataSource.data(myData);

Note that calling read method will repopulate the DataSource. In your case where local transport is used, this will result in filling  the DataSource with the initial (provided when it was created) data.Regards,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
KMILO
Top achievements
Rank 2
answered on 18 Jul 2012, 10:48 PM
Thanks Rosen, It works like a charm!!
0
Dennis
Top achievements
Rank 1
answered on 20 Jul 2012, 11:26 PM
How would I do it if I'm following the example code? My data is updating because when I click the search and retrieve the data it comes back wtih the changes.

Grid:
<div id="grid">
    @(Html.Kendo().Grid(Model)
        .Name("CodeManager")
    .Columns(columns =>
    {
        columns.Bound(p => p.CodeID);
        columns.Bound(p => p.Title);
        columns.Bound(p => p.Status);
        columns.Command(command => { command.Edit(); }).Width(200);
    })
    .ColumnMenu()
    .ToolBar(toolBar => toolBar.Create().Text("Add New Code"))
    .Sortable()
    .Scrollable()
    .Groupable()
    .Pageable()
    .Filterable()
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
    .Resizable(resize => resize.Columns(true))
    .DataSource(dataSource => dataSource
        .Ajax()
        .Events(events => events.Error("error_handler"))
        .ServerOperation(false)
        .Model(model => model.Id(p => p.Id))
         .Update(update => update.Action("Code", "CodeManager", new { classifications = @ViewBag.SelectedCatgory }))
         .Create(create => create.Action("Code", "CodeManager"))
        )
        .Editable(ed => ed.Mode(GridEditMode.PopUp))
        )
</div>


Controller: I tried called the get again after the update and that didn't work.
HttpPost]
        public ActionResult Code(CodeModel codeModel, string classifications)
        {
            if (ModelState.IsValid)
            {
 
                codeModel.Category = classifications;
                var code = codeModel.FromModel();
 
                if (code.Id > 0)
                    _codeRepository.Update(code);
                else
                    _codeRepository.Insert(code);
 
                var criterion = new Criterion("Category", Operator.Equals, codeModel.Category);
                var model = _codeRepository.GetList(criterion).ToModel();
 
                return View(model);
            }




Thanks
Dennis



Tags
Grid
Asked by
KMILO
Top achievements
Rank 2
Answers by
Rosen
Telerik team
KMILO
Top achievements
Rank 2
Dennis
Top achievements
Rank 1
Share this question
or