field type "datatable" not showing selected values

field type "datatable" not showing selected values

u01sfa3u01sfa3 Posts: 4Questions: 1Answers: 0

Hello,

I am using .NET Editor v2.0.5 and have a multi-select box. When the type of this is datatable, the selected values aren't displayed in the editor panel. If I switch the type from datatable to **select **or **checkbox **shows the correct selected values.

{
                        "label": "Categories:",
                        "name": "Categories[].id",
                        "type": "datatable",
                        "multiple": true
                    }

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    Can you give me a link to your page showing the issue so I can debug it please? If that isn't possible can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is.

    Allan

  • u01sfa3u01sfa3 Posts: 4Questions: 1Answers: 0

    Hi Allan,

    Thanks for getting back to me. The page isn't public facing but I have uploaded the debugger information, code: urizoz. Let me know if that's all you need?

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    That's really useful - thank you. I can see in it that the response from the server for the data in a row looks like:

            "Categories": [{
                "id": "1",
                "Name": "Engineering & Technology"
            }, {
                "id": "4",
                "Name": "Excel skills"
            }]
    

    While for the options it is:

            "Categories[].id": [{
                "value": 2,
                "label": "Engineering"
            }, {
    ...
    

    Note that the id property for the row is a string, while for the options it is an integer. I strongly suspect that is the issue since we use strict typing for the DataTable.

    How are you populating the JSON reply from the server?

    Allan

  • u01sfa3u01sfa3 Posts: 4Questions: 1Answers: 0

    Hi Allan,

    categories are populated in the controller as:

                 .MJoin(new MJoin("Categories")
                                    .Link("courses.id", "CourseCategories.CourseId")
                                    .Link("Categories.id", "CourseCategories.CategoryId")
                                    .Model<JoinAccessModel>()
                                    .Order("Categories.Name")
                                    .Field(new Field("id")
                                        .Options(new Options()
                                            .Table("Categories")
                                            .Value("id")
                                            .Label("Name")
                                        )
                                    )
                                )
    

    Would it be useful to have the full model & controller code?

    I appreciate your help with this.

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    I actually had exactly the same error in my Mjoin example for .NET - apologies for that.

    The error is in the JoinAccessModel - it should be:

        public class JoinAccessModel
        {
            public int id { get; set; }
    
            public string name { get; set; }
        }
    

    The error was being caused by the id property being marked as a string. If you change it to int then it should spring into action!

    Regards,
    Allan

  • u01sfa3u01sfa3 Posts: 4Questions: 1Answers: 0

    Hi Allan,

    That's great, thanks for your help with this. Much appreciated

Sign In or Register to comment.