jQWidgets Forums

jQuery UI Widgets Forums Lists ListBox AddItem and Group Information

This topic contains 4 replies, has 2 voices, and was last updated by  George S 8 years, 10 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • AddItem and Group Information #85242

    George S
    Participant

    For a listbox, I am pulling data from a database, doing some formatting work, and then wanting to add the data to one of 4 groups. I start with a completely empty ListBox, and then loop through all the rows (15-30) from the database. I can add the data to the listbox, but no GROUP information is showing up. All the rows show up as root entries. In looking at the FORUM, a post from Jan 2013 says that AddItem does not support GROUP, but looking at your API docs shows that it now does.

    Here is the applicable portion of code.

    
     var accountItem =  'Accounts / Subsidiaries';
     var parentItem =   'Parent Accounts';
     var ultimateItem = 'Ultimate Parent Accounts';
    
    // Make AJAX request to DB
    respAnalysis.done(function(data) {
    
        // Save away HOW MANY rows returned from the AJAX call
        var rowCount = data.rows.length;    
        
        for (i = 0; i < data.rows.length; i++) {         
            var grp = data.rows[i].DUNS_LEVEL;
            var duns_group;
            duns_group = 'EMPTY';
            if (grp === 'DUNS') {
                duns_group = accountItem;
            }
            if (grp === 'IMMEDIATE') {
                duns_group = parentItem;
            }
            if (grp === 'ULTIMATE') {
                duns_group = ultimateItem
            };
                
            $("#AnalysisBodyLeft").jqxListBox('addItem', { label: data.rows[i].COMPANY_NAME, value: 'AA' + i, group: duns_group }); 
            console.log(data.rows[i].COMPANY_NAME + '  :  ' + duns_group);               
        }; // end of FOR LOOP
    
    }); // end of RESP
    

    What I SHOULD be getting is 4 categories, each with 2-4 entries. What I am getting instead is all rows being added at a root level. The data is showing up as expected in the Console Log. What am I doing wrong?

    AddItem and Group Information #85250

    ivailo
    Participant

    Hi George S,

    Better use jqxDataAdapter and format the source in it’s beforeLoadComplete callback.
    Then you will avoid this behavior of addItem method and your items will be added correctly.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

    AddItem and Group Information #85262

    George S
    Participant

    Use another approach is a valid answer, but regardless, the API doc says that for Listbox.addItem, the GROUP functionality is supported and works. This means that I am either doing something wrong in my code, or the docs are wrong and it is not supported. Is there something wrong with the way I am calling Listbox.addItem?

    Thanks

    AddItem and Group Information #85273

    ivailo
    Participant

    Hi George S,

    Thanks for the feedback. We will consider this behavior.
    We also could offer you another workaround, simulating the behavior of addItem method.
    You can add your item directly to the source and then to refresh the widget. This way the item will be added at last position in the chosen group.

    Here is a demo.

    Best Regards,
    Ivailo Ivanov

    jQWidgets Team
    http://www.jqwidgets.com

    AddItem and Group Information #85985

    George S
    Participant

    AddItem did the job. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.