grid sorting-filtering and editing

2 posts, 0 answers
  1. Michael
    Michael avatar
    50 posts
    Member since:
    May 2014

    Posted 25 Dec 2017 Link to this post

    Hi,

    I have a property stakeHolder he is an object type of Developer.

    In my grid I want to add a product but the field stakeHolder is editable(false) and i put on it the name I want hard coded.

    The problem is if I use stakeHolder.Name then sorting and filtering work good but when i trying to add row then an error occurred " StakeHolder is not defined"

    and when I use stakeHolder then everything is working great except for sorting and filtering (as I know filtering/sorting don't work on object)

    what can I do?

    namespace TaskManagementUI.Models
    {
        public class Developer
        {
            public int? ID { get; set; }
            [Required(ErrorMessage = "Please enter a name")]
            [Display(Name = "Name")]
            public string Name { get; set; }
        }

    @(Html.Kendo().Grid<TaskManagementUI.Models.ProductViewModel>()
              .Name("GridProducts")
              .Columns(columns =>
              {
                  columns.Bound(c => c.ID).Hidden();
                  columns.Bound(c => c.Name).Title("Name").Width(200);
                  columns.Bound(c => c.CreateDate).Title("Creation date").Format("{0: MM/dd/yyyy}").Width(200);
                  columns.Bound(c=>c.StakeHolder.Name).Title("Creator").Width(200);
                  columns.Bound(c => c.Description).Title("Description").Width(250);
                  columns.Command(command => command.Custom("ADDPROJECT").Text("Add Project").Click("addProject")).Title("Add Project").Width(170).HtmlAttributes(new { id = "addProjectButton" });
                  columns.Command(command => { command.Edit().UpdateText("SAVE"); command.Destroy(); }).Width(250);

              })

                .Resizable(resize => resize.Columns(true))
                .Filterable()
               .ToolBar(toolbar =>
               {
                   toolbar.Excel();
                   toolbar.Create().Text("Add New Product");
               })
                .Editable(editable => editable.Mode(GridEditMode.InLine).TemplateName(""))
               .Excel(excel => excel
                              .AllPages(true)
                              .FileName("Products.xlsx")
                              .Filterable(true)
                              .ForceProxy(true)
                              .ProxyURL(Url.Action("FileExportSave", "Home")))
              .Pageable(pager => pager
                                .Refresh(true)
                                .PageSizes(true)
                                .PageSizes(new int[] { 6, 15, 20 })
                                .ButtonCount(5))
              .Sortable(sortable =>
              {
                  sortable.SortMode(GridSortMode.MultipleColumn)
                  .Enabled(true);
              })
              .Scrollable()
              .Events(e=>e.Edit("onProductEdit").Save("onProductSave").Cancel("onProductCancel").DataBound("onDataBoundSavedProducts"))
              .DataSource(dataSource => dataSource
                                       .Ajax()
                                       .PageSize(20)
                                       .Events(events => events.Error("errorHandlerProduct"))
                                      .Model(model =>
                                      {
                                          model.Id(item => item.ID);
                                          model.Field(a => a.StakeHolder.Name).DefaultValue(new Developer {ID=52,Name="Uriel Ash"}).Editable(false);
                                          model.Field(a => a.CreateDate).Editable(false);
                                      })
                                       .Read(read => read.Action("GetSavedProducts", "Product"))
                                       .Update(update => update.Action("UpdateProduct", "Product"))
                                       .Destroy(update => update.Action("DeleteProduct", "Product"))
                                       .Create(update => update.Action("CreateProduct", "Product"))))


  2. Alex Hajigeorgieva
    Admin
    Alex Hajigeorgieva avatar
    504 posts

    Posted 26 Dec 2017 Link to this post

    Hello, Michael,

    The observed behaviour is due to a default value missing for the complex object field StakeHolder.

    https://docs.telerik.com/kendo-ui/api/javascript/data/model#methods-Model.define

    You can supply it in the Kendo UI Data Source model definition, for example:

    .DataSource(dataSource => dataSource
    .Model(m=>
    {
      m.Id("ID");
      m.Field(f => f.StakeHolder).DefaultValue(new Developer() { ID = 0, Name = "Default" });
    })

    Let me know if you need further help.

    Kind Regards,
    Alex Hajigeorgieva
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top