Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8843367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:12:09+00:00 2026-06-14T11:12:09+00:00

tablesorter plugin duplicates data added to table from input form and then sorts by

  • 0

tablesorter plugin duplicates data added to table from input form and then sorts by clicking on header that duplicated data. after page refresh table shows entered data in order of entrance

can anyone help with this
http://jsfiddle.net/KrRyb/

thanks

window.BookView = Backbone.View.extend({
tagName: "tr",

events: {
},

template: $("#book-item").template(),

initialize: function(){
  _.bindAll(this, "render");
},

render: function(){
  var element = jQuery.tmpl(this.template, this.model.toJSON());
  $(this.el).html(element);
  return this;
  }
  });
  $(document).ready(function() 
  { 
    $("#books-table").tablesorter(); 
  } 
  ); 
window.AppView = Backbone.View.extend({
el: $("#app"),
events: {
  "click .tabs a": "tabs",
        "click #add-book": "createBook",
        "click .edit-book": "editBook",
        "click #update-book": "updateBook",         
        "click .delete-book": "deleteBook",
        "click #selectall": "selectAllBooks",
        "click .select": "selectBookRow",   
        "click #manage tbody tr": "selectBookRow",
        "click #deleteall": "deleteAll"                                                 
},

initialize: function(){
  _.bindAll(this, "render", "tabs", "addAll", "addBook", "createBook", "editBook",                "deleteBook");
        this.activeBookId = null;
        this.$("#create").show();
  Books.bind('add', this.addBook); 
  Books.bind('reset', this.addAll);
  Books.fetch();
},

selectAllBooks: function(el){
    var target = $(el.target), rows = this.$('#manage tr:not(#select-info)');
        if(target.is(':checked'))
        {
                 rows.css({background:"whiteSmoke"}).find('.select').prop("checked", true);
        }
        else
        {
             rows.css({background:"white"}).find('.select').prop("checked", false);
        }
        this.showSelected();
    },

    selectBookRow: function(el){
        var target = $(el.target), row = target.parents("tr"), checkbox =  row.find('.select');
        if(checkbox.is(':checked'))
        {
            row.css({background:"white"});
            checkbox.prop("checked", false);
        }
        else
        {
            row.css({background:"whiteSmoke"});
            checkbox.prop("checked", true);
        }
        this.showSelected();            
    },      

    showSelected: function(){
        var info = $('#select-info'), count = $('#manage     .select:checked').length, word = count>1?"books":"book",
            html = '<tr id="select-info"><td colspan="6">('+count+')   '+word+' selected. <a id="deleteall" href="javascript:void(0);">delete</a></td></tr>';
        if(Books.length>0)
        {
            if(info.length === 0)
            {
              $('#manage tbody').prepend(html); 
            }
            else if(count>0)
            {
                info.replaceWith($(html));
            }
            else
            {
                info.remove();
            }
        }   
    },

    deleteAll: function(){  
        $('#manage tbody').find('input:checked').each(function() {
            var that = $(this);
            Books.get(that.data('id')).destroy();
            that.parents('tr').remove();
        });
        $('#select-info').hide();
        $('#selectall').prop("checked", false);
    },

    tabs: function(e){
      var target = $(e.target);
      $('.tabs a').removeClass('active');
      target.addClass('active');
      this.$('.content').hide();
      if(target.attr('id') === "create-tab")
      {
        this.$("#create").show();   
      }
      else
      { 
          this.addAll();
            this.$('#selectall').prop("checked", false);
        this.$("#manage").show();       
      }
    },

    editBook: function(el){
        var target = $(el.target), book = Books.get(target.data('id'));
        this.activeBookId = target.data('id');
        $('#book-edit-form').find(':input[name]:enabled').each(function() {
            var self = $(this);
            self.val(book.attributes[self.attr('name')]);
        });
        this.$('.content').hide();
        this.$('#manage-edit').show();
    },

    updateBook: function(el){
        var target = $(el.target), data = {};
        $('#book-edit-form').find(':input[name]:enabled').each(function() {
            var self = $(this);
            data[self.attr('name')] = self.val();
        });
        Books.get(this.activeBookId).set(data).save();
        this.addAll();
        this.$('.content').hide();
        this.$('#manage').show();
    },

    deleteBook: function(el){
        var target = $(el.target);
        Books.get(target.data('id')).destroy();
        target.parents('tr').remove();
    },      

  addAll: function(){
      this.$("#manage table tbody").empty();    
    Books.each(this.addBook)
  },

  addBook: function(book){
    var view = new BookView({model: book});
    this.$("#manage table tbody").prepend(view.render().el);
  },

   createBook: function(e){
        var data = {};
        $('#book-form').find(':input[name]:enabled').each(function() {
            var self = $(this);
            data[self.attr('name')] = self.val();
            self.val("");
        });
        Books.create(data);
  }
   });

    window.App = new AppView();

   window.AppController = Backbone.Router.extend({

  initialize: function(){
    $('.tabs a').removeClass('active');
    this.mainView = new window.AppView
  },

  routes: {
    "create":"create",
    "books":"books"
  },

  create: function() {
    $('.tabs a#create').addClass('active');
  },

  books: function() {
    $('.tabs a#books').addClass('active');
  }

      });

     window.App = new AppController();
     Backbone.history.start();

     });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T11:12:10+00:00Added an answer on June 14, 2026 at 11:12 am

    It’s difficult to guess the problem you’re having, but I think if you put the tablesorter initialization code after the template renders, it might work…

    so change this:

        render: function(){
          var element = jQuery.tmpl(this.template, this.model.toJSON());
          $(this.el).html(element);
          return this;
        }
      });
        $(document).ready(function() 
        { 
            $("#books-table").tablesorter( {sortList: [[0,0], [1,0]]} ); 
        } 
    );
    

    to this:

        render: function(){
          var element = jQuery.tmpl(this.template, this.model.toJSON());
          $(this.el).html(element);
          // initialize tablesorter here
          $("#books-table").tablesorter( {sortList: [[0,0], [1,0]]} );
          return this;
        }
      });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the JQuery tablesorter plugin. The table has a column that shows dates
Im trying too append data to a table with the tablesorter plugin (http://tablesorter.com) Im
I have a table that generates perfectly using php, ajax and the tablesorter plugin.
I am using the jQuery tableSorter plugin on a page. Unfortunatley, the table that
I have a table that I've made sortable using the jQuery plugin Tablesorter 2.0
I want to use Christian Bach's tableSorter client-side table sorting jQuery plugin with my
I've got a table which Im sorting with tablesorter ( http://tablesorter.com ). Within that
I am using the jquery tablesorter plugin to sort a table. On of my
I'm using the jQuery tablesorter plugin to sort a table, which assigns .click() handlers
I am using a Jquery Tablesorter plugin for sorting a table.I want, when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.