jQuery UI Widgets Forums Lists ListBox Reordering items with custom renderer

This topic contains 2 replies, has 2 voices, and was last updated by  brojgar 8 years, 11 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • Reordering items with custom renderer #78616

    brojgar
    Participant

    I use a custom renderer with my Listbox. I get all my data fields I need for each ListBox item the same way you do in your Jsfiddle example at http://jsfiddle.net/jqwidgets/ANfqF/ :

    `renderer: function(index, label, value) {
    var datarecord = data[index];
    return “<span>” + datarecord.firstname + “</span>”
    },`

    It works. But if I make the list reordable with: allowDrop: true, allowDrag: true and then try moving the item, I get error:

    Uncaught TypeError: Cannot read property 'firstname' of undefined

    I can see that datarecord is not defined, but I can’t find an obvious way to pass my data (multiple fields) via (index, label, value).

    Thanks for your help!
    iztok

    Reordering items with custom renderer #78618

    Dimitar
    Participant

    Hello iztok,

    Please update the renderer function as follows and this functionality should work as expected:

    renderer: function(index, label, value) {
        var datarecord = data[index];
        if (datarecord) {
            var table = '<table style="min-width: 150px;"><tr><td>' + datarecord.firstname + " " + datarecord.lastname + '</td></tr><tr><td>' + datarecord.title + '</td></tr></table>';
            return table;
        }
    }

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Reordering items with custom renderer #78623

    brojgar
    Participant

    And indeed it does. Thank you and sorry for asking something with a quite obvious answer. But maybe you should also add this test to your jsfiddle example.
    iztok

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

You must be logged in to reply to this topic.