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

Grid popup edit issues

6 Answers 650 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eduardo
Top achievements
Rank 1
Eduardo asked on 24 Sep 2012, 05:59 PM
Hi,

I found two issues when set a grid in popup edit mode.

1- When inserting, updating or deleting an item, the DataSourceRequest parameter doesn't have any of the filters that the grid have before the operation, and then the results aren't filtered. I checked the http post request, and the filter, sort and group are empty.

Here's the controller:
[AcceptVerbs(HttpVerbs.Post)]
        public virtual JsonResult Insert([DataSourceRequestDataSourceRequest request)
        {
            var item = repository.CreateNew();
            try
            {
                UpdateModel(item);
                repository.Add(item);
                unitOfWork.SaveChanges();
            }
            catch (Exception err)
            {
                ...
            }
            return
                Json(repository.GetAll().ToDataSourceResult(request));
        }

2- I've a custom editor template with a kendo dropdownlist, and when I insert a new item, the field come with '0' value, instead of the default '1'. To get this to work, I've to always select an item of the dropdownlist.

Here's the dropdownlist in the editor template:
@(Html.Kendo()
                  .DropDownListFor(c => c.ID_COIN)
                  .BindTo(new SelectList((IEnumerable)ViewData["Coins"], "ID""DESCRIPCTION", 1)))

Eduardo

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 27 Sep 2012, 02:41 PM
Hello Eduardo,

Straight to your questions:
  1. The parameters are not sent because it is not needed to return the whole data when performing create, update or delete. When creating a new record you should return just a collection with the updated item so the DataSource can get the ID e.g.
    return Json(new [] { item }.ToDataSourceResult(request, ModelState));
  2. I am not sure what is causing this behavior is the default value set to the DataSource Model? For example:
    .DataSource(dataSource => dataSource
               .Ajax()
               .Model(model =>
                   {
                       model.Id(p => p.ID);
                       model.Field(f => f.ID_COIN).DefaultValue(1);
                   })
    If yes, could you share the code you are using or a small runnable sample so I can check the setup?


Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Eduardo
Top achievements
Rank 1
answered on 01 Oct 2012, 04:28 PM
First, thanks for your answer, it was helpfull, but not solved our problems.

Before get to the issues we are seeing, I need to explain the scenario we are working on.

We have several pages consisting on:
1 - A window that displays a grid with all the customers. The user can filter the customers data.
2 - A page grid with a custom toolbar for filtering elements according to a date. If the date is null or is greater than DateTime.Now, the element is active, otherwise is inactive.
3 - A toolbar page for filtering grid data acording to an customer id. All the grid models have this property.

So, the user can filter the grid in many ways: selecting a customer from the window, writing a customer id on the tollbar page input, or selecting an element in the page grid, or writing a name in the autocomplete of the toolbar page (in the sample is the input disabled, I quit these for simplicity). Behind all these funcionality works with your mvvm pattern, wich by the way is awesome.

I've attached a sample project that use northwind database(wich is not in the zip file) with a single page with the elements mentioned above an adapted to the database. The issues that we see are:
1 - If we set a default value for the grid model property that is display in the editor template as a dropdownlist, the problem '2' mentioned in my previous post is fixed, but this we consider is not a good design for this particular control, because we maybe don't know the default value, and the dropdownlist, when fetch it's data, select the first element, so the user can assume that this is the default value.
2 - We set the page grid to selection type 'Cell' to filter the data by the customer id of that row, but when we click in the edit or delete buttons, the change event fires, wich we don't want, because fires the filter event and close the editor window. Be the way, if selection type is 'Row', then the event fires even when you click the details button.
3 - Your response about the first issue of my previous post works almost fine, because we think that if the user has the grid filtered, then the new element need to be filtered too, wich could result in a new element not showin after the insert.
4 - Other details, like null values in grid and validation issues, we think are fixed in the sp1, according to changelogs.

We are considering to migrate all our mvc products to kendo, we think this library is much better than the previous telerik extension, wich we use, with some cool features, but we faced these problems when we start migrating a small mvc app for testing.

Sorry by theeese big post, and we are waiting for your response

Eduardo
0
Accepted
Daniel
Telerik team
answered on 04 Oct 2012, 03:30 PM
Hello again Eduardo,

Thank you for providing a sample project and the additional information. In answer to your questions:
  1. I am still not sure if I understand the exact scenario. Assigning the default value to the model will be done at the same time as setting the selected value to the SelectList. Could you clarify a bit more?
  2. I am afraid that currently there is not way to determine from the change event if an edit or delete button is pressed. It is possible to use custom click handler and check if a button or the expand icon is clicked:
    $(function () {
        var grid = $("#orders").data("kendoGrid");
        grid.tbody.on("click", "tr:not(.k-detail-row,.k-grouping-row)", function (e) {
            if (!$(e.target).is(".k-grid-edit,.k-grid-delete,.k-edit,.k-delete,.k-plus,.k-minus")) {
                //your logic
            }
        });
    })
  3. In order to filter the data again after creating a new item I can suggest to use the requestEnd event which is available in the service pack and read the data again when a create request is completed.
    function requestEnd(e) {
        if (e.type == "create") {
            this.read();
        }
    }
    An alternative would be to enable client operations with the ServerOperation DataSource method, but in this case the new item should have the filtered values. Otherwise it will not be shown.
  4. Showing null into the Grid cells or in the inputs is fixed in the service pack. What validation issues have you experienced with the official release?

Kind regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Eduardo
Top achievements
Rank 1
answered on 04 Oct 2012, 08:47 PM
Hi, Daniel

Going right to the matter:

1 - We are saying that it's a little confusing that we have to set the default value to the property when the dropdownlist's default behaviour is select the first value of the collection, so why I have to do this explicity?
2 - We found a similar way to avoid this when selection type is 'Cell', but thanks for these piece of code, will help us when the type used is 'Row'.
3 - We could use that in the future, unfortunately we don't have a kendo license, so we must wait for Q3 release, but basically it's the same thing that Telerik Extension do, only that we must do an additional ajax call. Maybe make this an optional behaviour of the dataSource? I think this scenario (a grid filtered and making inserts, updates, deletes) is pretty common.
4 - The other problems we belived are fixed, when we tried to insert a new item, the kendo widgets show something like 'the field must be a number' or date, etc

Thanks for your response,

Eduardo

0
Eduardo
Top achievements
Rank 1
answered on 05 Oct 2012, 09:52 PM
Hi,

Well, I've two more questions about kendo grid:
1 - I've a grid, and I want to set some properties of my model in the detail template, but I want to use another grid for that. The problem is went I set a date, the column show a strange data. I tried formating the value using kendo.toString, but that throw an error.
2- I've a model with a property of a complex type and I set the default values for that complex type in my model, but tha date gets a bad value. If I edit an existing record, I shows the date well.

Eduardo
0
Daniel
Telerik team
answered on 08 Oct 2012, 10:17 PM
Hello Eduardo,

Both problems are cause by using a complex type. Currently the DataSource schema supports only a single level and the type of the "FECHA" field will not be set to date. Therefore, the DataSource will not parse it and the value will be shown in the Microsoft date format. You should use a flattened view model without complex objects, in order to avoid this behavior. There is already a feature request to support related objects. You can vote for it and follow its progress on this page.

Regarding the your other questions:
  • The default value is needed, because the model will be set to the type's default value. So unless it is specified, the value of the dropdown will be  zero in this case. An alternative to setting a value would be to use an OptionLabel which will be selected when the default value is not matched.
  • Thank you for the suggestion about reloading the data. You may consider opening a feature request in our user voice forum

Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Eduardo
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Eduardo
Top achievements
Rank 1
Share this question
or