react-anything-sortable is a ReactJS component that can sort any component passed as this.props.children. It is compatible with IE8 and all modern browsers.
It has no external dependencies but React itself.
Sort custom style children
Sort images
Children with custom event handler
$ npm install --save react-anything-sortable
// or use bower
$ bower install --save react-anything-sortable
You can check the straight-forward demo by examining demo folder, or here's a brief example.
In YourComponent.jsx
var React = require('react');
var Sortable = require('react-anything-sortable');
var YourSortableItem = require('./YourItem');
React.renderComponent(
<Sortable onSort={handleSort}>
<YourItem sortData="1" />
<YourItem sortData="2" />
</Sortable>
, document.body);
and in YourItem.jsx
Notice: There's a breaking change in requring SortableItemMixin in version 0.2.0
var React = require('react');
var SortableItemMixin = require('react-anything-sortable').SortableItemMixin;
var YourItem = React.createClass({
mixins: [SortableItemMixin],
render: function(){
return this.renderWithSortable(
<div>your item</div>
);
}
});
- Specify your style for
SortableandSortable Items, checkdemo/style.css, it is NOT optional! - Don't forget the
this.renderWithSortablecall inYourItem.jsx - Specify
sortDatainYourItem.jsxso thatSortablecan return the sorted array - Add
onSortprops toSortableto be noticed when a sort operation finished - Since we can't track any children modification in
Sortable, you have to usekeyto force updateSortablewhen adding/removing children.
$ npm run test


