Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If two Grids are on the same page have aggregates for a field with the same name an ArgumentException is thrown.(MVC wrappers) #3582

Closed
simonssspirit opened this issue Sep 14, 2017 · 4 comments

Comments

@simonssspirit
Copy link
Contributor

Bug report

If two Grids are not the page and have aggregates for fields with the same name an ArgumentException is thrown.

Reproduction of the problem

More information with detailed description, steps and runnable example can be found in ticket: 1129790

The workarounds are:

  1. Add the hidden field to the grid (to the model) and aggregate sth (for ex: sum) for this field. (if you have more than 2 grids with such problem, don't forget that these hidden fields must have different names, otherwise, it won't help)
  2. You can rename a field in one of the grids
  • Browser: [all]
@Thorlake
Copy link

Thorlake commented Nov 3, 2017

Sorry guys that I distract you, but almost two months have passed and no one has assigned this ticket.
For me it's a fatal error :/ Of course I've fixed this error and recompiled Kendo MVC project for myself, nevertheless I can't predict future problems of my fix (I suppose there are no problems, but... it's better to check your version too)
p.s. I just moved "rwLock.UpgradeToWriterLock" from method "CreateDynamicClass" in method "GetDynamicClass" (class "ClassFactory") before checking a key in dictionary with name "classes"
I don't know how other people work with current Kendo MVC (btw, this error still exists in new versions)
I have N grids with similar aggregates and unfortunately even their models are equal

Looking forward to your reply, have a nice day

@Alex-Bubblemaster Alex-Bubblemaster changed the title If two Grids are not the page and have aggregates for a field with the same name an ArgumentException is thrown.(MVC wrappers) If two Grids are on the same page have aggregates for a field with the same name an ArgumentException is thrown.(MVC wrappers) Nov 6, 2017
@Alex-Bubblemaster
Copy link
Contributor

Alex-Bubblemaster commented Nov 6, 2017

Also encountered in the thread with ID 1138380. raising the priority. Error thrown is "An item with the same key has already been added."

@ag-petrov ag-petrov self-assigned this Dec 20, 2017
@MilenaCh MilenaCh closed this as completed Jan 2, 2018
@MilenaCh MilenaCh added this to the 2018.R1 milestone Jan 2, 2018
@jrummell
Copy link

I'm still seeing this in 2018.2.620.545

@Alex-Bubblemaster
Copy link
Contributor

@jrummell - I am sorry we did not see your comment here. It would have been better to report this in the support channels so we could have reacted quicker.

Reported in ticket with ID: 1381826

I am able to reproduce this with R1 2018. It is easy to miss this one when testing because the error is thrown only the first time. Steps:

  • Create a project with two grids which have the same aggregate names
  • Copy paste this grid, changing only its name, e.g. "GridTwo"
  • Run the project (clean run from scratch rather than Ctrl + F5)

image

@(Html.Kendo().Grid<AjaxGridWithSelection.Models.OrderViewModel>()
                      .Name("GridOne")
                      .HtmlAttributes(new { @style = "height: 80%" })
                     .Columns(columns =>
                     {
                         columns.Bound(p => p.OrderID).Filterable(false);
                         columns.Bound(p => p.Freight);
                         columns.Bound(p => p.ShipName);
                         columns.Bound(p => p.ShipCity);
                     })
                     .DataSource(ds => ds
                         .Ajax()
                         .PageSize(20)
                         .Read(read => read.Action("Orders_Read", "Grid"))
                        .Model(m=>m.Id("OrderID"))
                     .Aggregates(aggregates =>
                     {
                         aggregates.Add(a => a.Freight).Sum();
                     })
            )
            .Scrollable()
            )

Workaround

  • Set GridTwo with AutoBind(false)
  • Add dataBound event handler and read GridTwo data source
 @(Html.Kendo().Grid<OrderViewModel>()
       .Name("GridOne")
       .Events(e=>e.DataBound("onDataBound"))
 )

 @(Html.Kendo().Grid<OrderViewModel>()
       .Name("GridTwo")
       .AutoBind(false)
 )
<script>
    function onDataBound(e){
        $("#GridTwo").data("kendoGrid").dataSource.read();
    }
</script>

  • Use models with different names

@boyandim boyandim self-assigned this Feb 13, 2019
@MilenaCh MilenaCh modified the milestones: 2018.R1, 2019.R1.SP.next Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants