Comments (10)
I managed to find a workaround after posting the issue, I just forgot to post the solution.
Before doing any changes to the table, you can "un-initialize" the table first using this line of code here:
document.getElementById("InsertYourTableIDHere").setAttribute("data-sortable-initialized", "false");
Or in jQuery it would be: $("#InsertYourTableIDHere").attr("data-sortable-initialized", "false");
After you are done changing the table, just run Sortable.init();
again.
from sortable.
+1
from sortable.
I've been going over https://github.com/HubSpot/sortable/blob/master/js/sortable.js and it doesn't seem like it exposes any methods to re-initialize, but it should be possible to re-init and things should "just work?"
I'm using RiotJS and I believe on re-draw it destroys the components
from sortable.
I haven't tried to add rows to the table "manually", but in combination with vue.js sorting seems to work even when the table is modified after init. It just does not trigger an automatic resort when new items are added - the user has to click on a header to trigger a resort. It would be nice to have an option to trigger this automatically. So far all sorting seems to be encapsulated in the "onClick" handler - so there is no obvious way to trigger this in code.
from sortable.
Woo! Thanks so much!
It does suck that the sorting doesn't re-sort the proper column, hrmmm
from sortable.
You can easily keep track of which column was last sorted using the column's ID or data attribute, and then programmatically sort the table after changing it.
On Wed, Mar 9, 2016 at 9:34 AM -0800, "Eric Carmichael" [email protected] wrote:
Woo! Thanks so much!
It does suck that the sorting doesn't re-sort the proper column, hrmmm
—
Reply to this email directly or view it on GitHub.
from sortable.
Hrm, trying to do something similar by manually firing the click-to-sort event:
sorted_column.dispatchEvent(new Event('onclick'));
sorted_column.dispatchEvent(new Event('onclick'));
Doesn't seem to actually work? Also, it seems like Sortable isn't sorting some columns properly, may have to specify a type somewhere? EDIT Actually maybe it is working, just some columns aren't sorting properly in the first place?
4146.57 should be the first row when sorted ascending
from sortable.
As far as I remember, to sort the table programmatically, all you do is give the column you want to sort a certain data attribute. Try sorting a table manually and then use inspector to see what attribute the column was given, then do the same using JavaScript or jQuery.
On Wed, Mar 9, 2016 at 9:46 AM -0800, "Eric Carmichael" [email protected] wrote:
Hrm, trying to do something similar by manually firing the click-to-sort event:
sorted_column.dispatchEvent(new Event('onclick'));
sorted_column.dispatchEvent(new Event('onclick'));
Doesn't seem to actually work? Also, it seems like Sortable isn't sorting some columns properly, may have to specify a type somewhere?
4146.57 should be the first row when sorted ascending
—
Reply to this email directly or view it on GitHub.
from sortable.
Cool, added data-sortable-type="numeric"
to my <th>
and it's all working now, you're the best thanks so much for your time!
from sortable.
Yeah, I am having the same issue when I add new rows to the table. Seems like the table could go through a re-initialization process, unhooking any events and clearing the value in _results, then initializing the table again, instead of calling
if (table.getAttribute('data-sortable-initialized') === 'true') {
return;
}
from sortable.
Related Issues (20)
- Publish sortable on npm HOT 2
- Only sorts the first tbody
- Sort handler triggered twice on mobile HOT 1
- first sorting column -- bug or feature? HOT 4
- no support for multiple header rows HOT 2
- trouble with manual install directions? HOT 1
- make first column static HOT 2
- Mobile support HOT 5
- Money? HOT 1
- Locale Date field not sorting
- IE8 Compatibility
- Radio Input losing Checked status
- Sort fails for table inside table cell
- touch devices fires sorting twice HOT 3
- Documentation
- Pagination and performance for larger datasets HOT 1
- 为什么使用ng-repeat出来的不能排序
- Sorting does not work with colspans in header
- Merge PRs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sortable.