How to retain the form values in Backbone js?

92 Views Asked by At

I have a customer-listing page with a filter button and the button will trigger a dialog to input the parameters for search.

Once I apply the filter (ajax process), the results are filtered and displayed properly the dialog is closed.

Since I have pagination, on paginating to the next page the filter parameters are not found as the dialog is closed.

Now how do I overcome this issue and retain the form data? Please advise! Thanks!

BTW, I'm using tablesorterPager for paginating

tablesorterPager({  
    container: $('#pager'),
    removeRows: true,
    page: 0,
    size: 10,
    savePages: false,
    ajaxUrl: utrl,
    customAjaxUrl: function(table, url) {
        //The below serailize is where the input for search form resides and doesn't work for the second page pagination.
        return url += '&'+$('[name="search_filter"]').serialize();
    },
    ajaxProcessing: function (data) {
        if (data[0] === 0) {
            return false;
        }
        return data;
    }
})
1

There are 1 best solutions below

0
T J On

You can save filter params in a Backbone model, something along the lines of

// When closing the filter dialog, save the values
const filterParamsModel = new Backbone.Model();

filterParamsModel.set({
  filterTitle: 'hello',
  filterBy: $('#someInput').val()
});


// Later during pagination

customAjaxUrl: function(table, url) {]
   return url += '&' + = jQuery.param(filterParamsModel.toJSON());
},