meskobalazs
meskobalazs

Reputation: 16041

How to reload data in a Fuel UX repeater

I am using the newly released Fuel UX 3.1 in a web application. I managed to set up a Repeater widget with data coming from the backend, however I can only render it once.

$('#myRepeater').repeater({
    dataSource: dataSource
});

So this block of code renders the repeater, however I cannot change the dataSource after this and render it again with the new values.

Upvotes: 1

Views: 1032

Answers (2)

StexGroup
StexGroup

Reputation: 106

You can try calling

$('#myRepeater').repeater('render') 

to reload dataSource; works for me.

Upvotes: 4

meskobalazs
meskobalazs

Reputation: 16041

Well, it does not really answer my original question, however this solves my problem. When I want to reload the Repeater with other data, I actually create a new one, with another dataSource.

So new my Ajax request to the server looks like this

$.ajax({
    url: '...some url...',
    type: 'post',
    data: JSON.stringify(payload),
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    success: function (data) {
        var dataSource = new MyDataSource(data, columns);
        // the repeater already exists
        if ($('#myRepeater .repeater-canvas').contents().length !== 0) {
            var enclosingDiv = $('#myRepeater').parent();
            var markup = $('#myRepeater').repeater('destroy');
            enclosingDiv.html(markup);
        }
        // creating the repeater normally
        $('#myRepeater').repeater({
            dataSource: dataSource
        });
    }
});

If someone is curious about MyDataSource, it is actually a simple function, which allows me to put my data into the dataSource function, expected by the Fuel UX repeater:

var MyDataSource = new function (data, columns) {
    return function (options, callback) {
        ...
    }
}

Upvotes: 0

Related Questions