Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a Kendo grid update even when no data is updated

I'm trying to upload an image for a product in Kendo grid (inline editing). In insert it's working fine. In update it's not allowing me to change only the image. After I click the update button, it's not going to the controller unless I change one of the other fields.

So if there is a way to force the update button to go to the controller it will be helpful.

@(Html.Kendo().Grid(Model)
    .Name("BrandGrid")
                    .Events(e => e.Edit("edit").DataBound("onDataBound").Cancel("onDataBound")) 
            .DataSource(dataSource => dataSource

                .Ajax()
                .ServerOperation(true)
                .Events(events => events.Error("error_handler"))


                .PageSize(10)
                   .Model(  model =>{
                       model.Id(p => p.BrandID);
                       model.Field(p => p.BrandID).Editable(false);


                   })

                   .Update(update => update.Action("Brand_Update", "Brands"))
                   .Create(insert => insert.Action("Brand_Insert", "Brands"))
                   .Read(read => read.Action("Brand_Read", "Brands"))
                   .Destroy(delete => delete.Action("Brand_Delete", "Brands"))

            )
         .Columns(columns =>
         {
             columns.Bound(p => p.BrandID).Groupable(false).Title(MyResources.LabelBrandID).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandNameE).Title(MyResources.LabelBrandNameE).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandNameA).Title(MyResources.LabelBrandNameA).HeaderHtmlAttributes(new { style = "text-align:" + MyResources.HeaderDirection });
             columns.Bound(p => p.BrandID).Width(120).Title(" ").Filterable(false)
            .ClientTemplate(@"<img alt='Brand Image' src='" + Url.Content("~/Images/Brands/") + "#=data.BrandID#.jpg' alt=\"${data.BrandID}\" />");

             columns.Template(@<text></text>).Title(" ").ClientTemplate("<input type=file name='files' onchange='dataBound(this.value)' />").Width(280).Hidden(true);                 
             columns.Command(command => { command.Edit().Text(MyResources.EditText).CancelText(MyResources.CancelText).UpdateText(MyResources.UpdateText); command.Destroy().Text(MyResources.Delete); });



         })

                             .ToolBar(toolbar => toolbar.Create().Text(MyResources.AddNewItem))
                     .Pageable(pager => pager
                    .Numeric(true)
                        .PreviousNext(true)
                        .Refresh(true)
                        .PageSizes(true)
                  )



                             .Filterable(filterable => filterable
                                .Extra(true)
                                .Operators(operators => operators
                                   .ForString(str => str.Clear()
                                   .StartsWith(MyResources.StartsWith)
                                   .IsEqualTo(MyResources.IsEqualTo)
                                   .IsNotEqualTo(MyResources.IsNotEqualTo)
                                   .Contains(MyResources.Contains)
                                   .DoesNotContain(MyResources.DoesNotContain)
                                   .EndsWith(MyResources.EndsWith)
                                    )
                                   .ForNumber(num => num.IsEqualTo(MyResources.IsEqualTo).IsGreaterThan(MyResources.IsGreaterThan).IsNotEqualTo(MyResources.IsNotEqualTo).IsGreaterThanOrEqualTo(MyResources.IsGreaterThanOrEqualto).IsLessThanOrEqualTo(MyResources.IsLessThanOrEqualTo).IsLessThan(MyResources.IsLessThan))
                                   )

                              .Messages(messages => messages.Info(MyResources.Info).Filter(MyResources.Filter).Clear(MyResources.Clear).And(MyResources.And).Or(MyResources.Or))
                                  )

                           .Pageable(pager => pager.Messages(messages => messages.Display(MyResources.Display).Empty(MyResources.Empty).First(MyResources.GoToTheFirstPage).Last(MyResources.GoToTheLastPage).Next(MyResources.GoToTheNextPage).Previous(MyResources.GoToThePreviousPage).Of(MyResources.of).Page(MyResources.page).ItemsPerPage(MyResources.ItemsPerPage).Refresh(MyResources.Refresh)))


                .Selectable(selectable => selectable
                .Mode(GridSelectionMode.Multiple))
                .Navigatable()
                .Sortable()
                .Scrollable(scr => scr.Height(405))
                .Resizable(resize => resize.Columns(true))
                //.HtmlAttributes(new { style = "height:430px;" })
                                        .Editable(editablee => editablee.Mode(GridEditMode.InLine).DisplayDeleteConfirmation(MyResources.DeleteConfirmMessage))

                )
like image 884
Wael Joulani Avatar asked Oct 01 '13 11:10

Wael Joulani


People also ask

How do I refresh Kendo grid after Ajax call?

You should use the transport configuration for this, have a create url. After you insert a new item in the datasource, just call sync() and let the magic happen.

What is Databound event in kendo grid?

Fired when the widget is bound to data from its data source. The event handler function context (available via the this keyword) will be set to the widget instance.

What is Pageable in kendo grid?

kendo:grid-pageable-messagesThe text messages displayed in pager. Use this option to customize or localize the pager messages. More documentation is available at kendo:grid-pageable-messages.


1 Answers

Kendo UI only update records if they are dirty which means that some of the fields in the model have been modified.

If you do not change the model but directly the data in the array, then KendoUI doesn't know that the record has actually been modified (that's why we have to use set, for controlling if dirty needs to be switched to true).

Not sure how you change image I agree with @PeturSubev that maybe would be easier if you share your code because we can see what is wrong.

If this is not possible you can force a dataItem to get dirty by doing:

// item is the reference to the data in the Grid DataSource
data.dirty = true;
$("#grid").data("kendoGrid").saveChanges();

Example in here : http://jsfiddle.net/OnaBai/pPkWc/

like image 78
OnaBai Avatar answered Sep 29 '22 06:09

OnaBai