Follow up on Dynamic loading of grid.

Dec 27, 2013 at 1:21 AM
Hi TPeczek,
I have been playing with the dynamic loading of the grid and it has been great and made a lot of my work much easier. After playing for it for a bit I noticed one thing. When I pass the model into the JqGridHelper the order that the properties are declared inside the model is the same order as the columns displayed in the grid. Is there a way, maybe some annotation, to change this? For example the model used is
    public class Model
    {

        public string Prop1 { get; set; }
        public string Prop3 { get; set; }
        public string Prop2 { get; set; }
    }
The grid will display the columns in that order, Prop1, prop3, prop2. I am looking for a way to make it display Prop1, Prop2, Prop3 with out having to change the order inside the model. Is there currently a way to do this?
Coordinator
Dec 27, 2013 at 10:35 AM
You can use the Order property of standard DisplayAttribute:
public class Model
{
    [Display(Order = 1)]
    public string Prop1 { get; set; }

    [Display(Order = 3)]
    public string Prop3 { get; set; }

    [Display(Order = 2)]
    public string Prop2 { get; set; }
}
Marked as answer by Eagle_f90 on 12/27/2013 at 6:25 PM
Dec 28, 2013 at 1:25 AM
Edited Dec 28, 2013 at 1:30 AM
Thanks that worked, but I think I also found a bug. If you are passing in a [HiddenInput] but do not specify an order number for it the grid will not create a column for it but the data will still be displayed. Code example:
public class Model
{
    [HiddenInput]
    public string ID {get; set;}

    [Display(Order = 1)]
    public string Prop1 { get; set; }

    [Display(Order = 3)]
    public string Prop3 { get; set; }

    [Display(Order = 2)]
    public string Prop2 { get; set; }
}
This will generate a grid with 3 columns but the first column would get date from the ID, the second from Prop1, and the 3rd from Prop2, and not display anything from prop3. But if you add a DisplayOrder, which is lower then the first column you do want to display, then the data stay hidden
Coordinator
Dec 28, 2013 at 6:47 PM
I will look into this.
Coordinator
Jan 28, 2014 at 11:00 AM
I'm sorry, I was unable to reproduce the issue.