Bind to dynamic object or bind to custom class with child classes

Posted by: mnorman on 23 October 2017, 6:48 pm EST

    • Post Options:
    • Link

    Posted 23 October 2017, 6:48 pm EST

    Hi

    I am trying to display a grid in MVC with custom columns that are based on the class defined in the model. I have tried to use a class with child classes that define the columns in a foreach loop and I have also tried using a dynamic class to specify all the individual columns but neither of these seem to work. Does anybody have any ideas on how this could be achieved?

  • Posted 24 October 2017, 8:15 pm EST

    Hi Matthew,

    You can show all the columns available in the model by generating columns automatically. Please refer to the code snippet:

    @(Html.C1().FlexGrid<Sale>()
        .Id("ovFlexGrid")
        .AutoGenerateColumns(true)
        .AllowSorting(Convert.ToBoolean(optionsModel.Options["Allow Sorting"].CurrentValue))
        .SelectionMode((SelectionMode)Enum.Parse(typeof(SelectionMode), optionsModel.Options["Selection"].CurrentValue))
        .Bind(bl => bl.InitialItemsCount(100).Bind(Model))
        .CssClass("grid")
        .IsReadOnly(true)
    )
    

    You can also show specific column in FlexGrid by setting autoGenerateColumns to false and defining columns.

    Please refer to the http://demos.componentone.com/ASPNET/MVCExplorer/FlexGrid for the same.

    ~Manish

  • Posted 24 October 2017, 10:39 pm EST

    Hi Manish,

    Sorry I probably should have clarified this a bit better. I have managed to bind the grid to a model that was made to a custom class and also contains child classes. The data displays correctly in the grid however if I enable editing and try to make a change to a field that is a member of the child class, this does not appear to passthrough to the controller

    Matt

  • Posted 25 October 2017, 10:47 pm EST

    Hi,

    The team is investigating on this.

    We will update you as get any update.

    ~Manish

  • Posted 26 October 2017, 10:38 pm EST

    Hi Matthew,

    If we understand correctly, you have applied deep binding (e.g obj.item) and when you edit the column that is bounded to the child class, the changes retains in FlexGrid but you can not get in Controller.

    If yes, it is by design since CollectionView tracks only shallow changes. In this case, you need to code to detect that changes.

    Please refer to the following thread that contains same discussion with a solution.

    https://www.grapecity.com/en/forums/wijmo/trackchanges-on-nested-col_1

    In case if it does not works for you, please share a demo sample with us so that we can investigate and suggest a solution accordingly.

    ~Manish

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels