locked
Grouped Binding.List displays the wrong groups for some attributes

    Question

  • Okay, I'm using a slightly customized variant of the example code for the grouped listview.

    The actual functions to create the grouped List are identical (safe for the attribute name).

    What I'm trying to create is a list of my pupils, sorted by their firstname. However, for an example list of 6 pupils, only half of them are put in the proper group but are instead put into a group of another pupil (sort of like musical chairs).

    At first I thought the reason might be that I'm pulling the data asynchronously (which means that for a short time, the firstname property is undefined).

    However, when I switched to grouping by the lastname property, the list actually groups correctly.

    Both first- and lastname property of each item is set at the same time and in an exactly identical manner. I included two snapshots to illustrate the problem, the template always display "lastname, firstname". First picture is grouped by lastname.

    Second picture is grouped by firstname:

    Below is the code to create the grouping, as I said, almost directly taken from the example code. Only real modification was the check for undefined. Currently the problematic code is commented out.

    function compareGroups(leftKey, rightKey) {
            return leftKey && rightKey && leftKey.charCodeAt(0) - rightKey.charCodeAt(0);
        }
        function getGroupKey(dataItem) {
            return dataItem.lastname && dataItem.lastname.toUpperCase().charAt(0);
            //return dataItem.firstname && dataItem.firstname.toUpperCase().charAt(0);
        }
        function getGroupData(dataItem) {
            /*return {
                title: dataItem.firstname && dataItem.firstname.toUpperCase().charAt(0)
            };*/
            return {
                title: dataItem.lastname && dataItem.lastname.toUpperCase().charAt(0)
            };
        }
        var pupilsList = new WinJS.Binding.List({ binding: true });
        var groupedPupilsList = pupilsList.createGrouped(getGroupKey, getGroupData, compareGroups);

    I'm a bit confused as to where exactly this problem is coming from.

    edit: I just entered a few more pupils and the same problem now is cropping up for the lastnames as well. Grml.

    edit2: Using dispatchEvent("reload") to either the original List or the GroupedList doesn't change the ordering. Also, as far as I can tell, the getGroupKey() function does return the proper values (that is, as soon as the property is not undefined anymore).

    edit3: Refactored the code so that the properties in question are no longer undefined (which means that I'm actually using identical code to the example!). Problem persists.

    edit4: Using createSorted() works just fine.

    • Edited by Rhywden Saturday, March 29, 2014 9:18 PM
    Saturday, March 29, 2014 6:51 PM

Answers

  • Kraig Brockschmidt (seemingly from Microsoft) was so kind as to help me out on StackOverflow. The source seems to have been a non-obvious localization issue which could be fixed by simply using this one line of code, followed by extending the functionality of the GetGroupKey function as follows:

    var charGroups = Windows.Globalization.Collation.CharacterGroupings();
    
    function getGroupKey(dataItem) {
            return charGroups.lookup(dataItem.lastname.toUpperCase().charAt(0));
        }



    • Edited by Rhywden Tuesday, April 8, 2014 4:53 PM
    • Marked as answer by Rhywden Tuesday, April 8, 2014 5:03 PM
    Tuesday, April 8, 2014 4:53 PM

All replies

  • Hi,

    what's meaning about createSorted()? Do you mean you can resolve your problem successfully?

    Best Wishes! 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, March 31, 2014 9:21 AM
  • No, my issue is not resolved. I merely sidestepped it by using a Sorted list instead of a Grouped list.
    Friday, April 4, 2014 10:03 PM
  • Kraig Brockschmidt (seemingly from Microsoft) was so kind as to help me out on StackOverflow. The source seems to have been a non-obvious localization issue which could be fixed by simply using this one line of code, followed by extending the functionality of the GetGroupKey function as follows:

    var charGroups = Windows.Globalization.Collation.CharacterGroupings();
    
    function getGroupKey(dataItem) {
            return charGroups.lookup(dataItem.lastname.toUpperCase().charAt(0));
        }



    • Edited by Rhywden Tuesday, April 8, 2014 4:53 PM
    • Marked as answer by Rhywden Tuesday, April 8, 2014 5:03 PM
    Tuesday, April 8, 2014 4:53 PM