Skip to content
Advertisement

Why are all tables sorted although only the first one is clicked?

I am creating a custom table for my application, which is sortable. The problem comes when i have multiple sortable tables.

The sorting of the last table works fine, but when I click on the first table header all the other tables also gets sorted.

All the sorting and filtering I did is inside the below library

JavaScript

I just want to know why other tables are getting sorted when I click on the first table, and how I can solve this.

JavaScript
JavaScript

Here is my Fiddle for the above code.

Advertisement

Answer

In your click handlers you select all .SortTableHeader and therefor the action for each div is bound to each header. You have to specify which header is meant:

JavaScript

Working example:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement