Search code examples
ruby-on-railsbackbone.jspaginationgmaps4railsbackgrid

Backbone Paginator click event


I am new to backbone and am using backbone in my rails application . This is what I am doing in my application

I am using Backbone Paginator for pagination support in my application as well using Gmaps for rendering locations on gmaps , for each time I am displaying 5 records from the server with pagination and displaying corresponding 5 location in map view , so now I need to show the remaining locations on map when I click on paginated links (prev page , next page) , I think I need to write some click events , but I am not sure where to write and how to write this events , Can any one please help me . please review the code below I have written evnets but those are not working

Thanks in advance

var Listings = Backbone.PageableCollection.extend({
    model: Bdemo.Models.Listing,

    mode: "server" ,

    url: '/listings' ,

    events: {
      "click #paginationSelect" : "fetchSelectedData"
    },

    fetchSelectedData: function(){
      console.log("CAMEEEEEEEEEEEEEEEEEEEEEEEEEEE")
    },

    // Initial pagination states
    state: {
      pageSize: 3,
     /* sortKey: "updated",*/
      order: 1
    },


    queryParams: {
      totalPages: null,
      totalRecords: null,
      sortKey: "sort"
    },



    parseState: function (resp, queryParams, state, options) {
      return {totalRecords: resp.total_pages};
    },


    parseRecords: function (resp, options) {
      return resp.listings;
    }

  });

Solution

  • Hi finally solved this by calling my own function(callGmap) from Backbone.PageableCollection , here is my new code

    var Listings = Backbone.PageableCollection.extend({
        model: Bdemo.Models.Listing,
    
        mode: "server" ,
    
        url: '/listings' ,
    
        events: {
          "click #paginationSelect" : "fetchSelectedData"
        },
    
        fetchSelectedData: function(){
          console.log("CAMEEEEEEEEEEEEEEEEEEEEEEEEEEE")
        },
    
        // Initial pagination states
        state: {
          pageSize: 3,
         /* sortKey: "updated",*/
          order: 1
        },
    
    
        queryParams: {
          totalPages: null,
          totalRecords: null,
          sortKey: "sort"
        },
    
    
    
        parseState: function (resp, queryParams, state, options) {
          return {totalRecords: resp.total_pages};
        },
    
    
        parseRecords: function (resp, options) {
          callGmap(resp.hash);
          return resp.listings;
        }
    
      });