Skip to content

Commit 8587eb7

Browse files
committed
add movable ability on aha-table.
1 parent f3e6f02 commit 8587eb7

File tree

6 files changed

+120
-20
lines changed

6 files changed

+120
-20
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <aha-table> ![Bower Version](https://badge.fury.io/bo/aha-table.svg)
22

3-
> A Polymer element for a searchable, sortable, paginatable, inline-editable, selectable, copyable, removable table/grid.
3+
> A Polymer element for a searchable, sortable, paginatable, inline-editable, selectable, copyable, removable, movable table/grid.
44
55
## Demo
66

@@ -43,6 +43,8 @@ Or [download as ZIP](https://github.com/liuwenchao/aha-table/archive/master.zip)
4343
<aha-table
4444
selectable
4545
copyable
46+
removable
47+
movable
4648
seachable
4749
pagesize="20"
4850
pagesizetitle="Page Size:"
@@ -71,12 +73,15 @@ Attribute | Options | Default | Description
7173
`searchable` | *Boolean* | False | if search row is displayed
7274
`copyable` | *Boolean* | False | if copy handler is displayed
7375
`removable` | *Boolean* | False | if remove handler is displayed
76+
`movable` | *Boolean* | False | if move up/down handler is displayed
7477
`pagesize` | *Number* | 10 | record set size for each page
7578
`data-sizelist` | *Array* | [5, 10, 20, 50, 100] | list for page size dropdown
7679
`selecttitle` | *String* | undefined | title for select checkbox
7780
`selectalltitle`| *String* | undefined | title for selectall checkbox
7881
`copytitle` | *String* | undefined | title for copy indicator
79-
`deletetitle` | *String* | undefined | title for remove indicator
82+
`removetitle` | *String* | undefined | title for remove indicator
83+
`movedowntitle` | *String* | undefined | title for move down indicator
84+
`moveuptitle` | *String* | undefined | title for move up indicator
8085
`sorttitle` | *String* | undefined | title for sortable column
8186
`edittitle` | *String* | undefined | title for editable data cell
8287
`searchtitle` | *String* | undefined | title for search filter row toggler
@@ -104,6 +109,10 @@ Name | Arguments | Description
104109
`after-copy` | `Event` | call after a record is copyed from another internally
105110
`before-remove` | `Event` | call before a record is removed internally
106111
`after-remove` | `Event` | call after a record is removed internally
112+
`before-move-down` | `Event` | call before a record is moved down
113+
`after-move-down` | `Event` | call after a record is moved down
114+
`before-move-up` | `Event` | call before a record is moved up
115+
`after-move-up` | `Event` | call after a record is moved up
107116

108117

109118
## &lt;aha-column&gt;
@@ -157,7 +166,7 @@ In order to run it locally you'll need to fetch some dependencies and a basic se
157166
3. To test your project, start the development server and open `http://localhost:8000`.
158167

159168
```sh
160-
$ grunt
169+
$ grunt server
161170
```
162171

163172
4. Once you finish developing it, build the distribution files and publish it on Bower.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "aha-table",
3-
"version": "1.1.0",
4-
"description": "Polymer Element for aha-table, a searchable, sortable, editable, selectable, paginatable, copyable, removeable table/grid.",
3+
"version": "1.1.1",
4+
"description": "Polymer Element for aha-table, a searchable, sortable, editable, selectable, paginatable, copyable, removeable, movable table/grid.",
55
"authors": [
66
"Louis Liu"
77
],

demo/theme-shim.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#themed .search,
6262
#themed .nosearch,
6363
#themed .copy-er i,
64+
#themed .move-down-er i,
65+
#themed .move-up-er i,
6466
#themed .remove-er i
6567
{
6668
border: 0;
@@ -88,4 +90,10 @@
8890
}
8991
#themed .remove-er i:before {
9092
content:"\f014";
93+
}
94+
#themed .move-down-er i:before {
95+
content:"\f063";
96+
}
97+
#themed .move-up-er i:before {
98+
content:"\f062";
9199
}

demo/theme.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
#themed::shadow .search,
6262
#themed::shadow .nosearch,
6363
#themed::shadow .copy-er i,
64+
#themed::shadow .move-down-er i,
65+
#themed::shadow .move-up-er i,
6466
#themed::shadow .remove-er i
6567
{
6668
border: 0;
@@ -88,4 +90,10 @@
8890
}
8991
#themed::shadow .remove-er i:before {
9092
content:"\f014";
93+
}
94+
#themed::shadow .move-down-er i:before {
95+
content:"\f063";
96+
}
97+
#themed::shadow .move-up-er i:before {
98+
content:"\f062";
9199
}

index.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ <h2>Advanced usage: themed, customized columns, customized attributes, customize
3636
searchable
3737
copyable
3838
removable
39+
movable
3940

4041
pagesize="5"
4142
data-sizelist="[2,5,10]"
@@ -53,6 +54,8 @@ <h2>Advanced usage: themed, customized columns, customized attributes, customize
5354
edittitle="click to edit"
5455
copytitle="click to copy"
5556
removetitle="click to remove"
57+
movedowntitle="move down"
58+
moveuptitle="move up"
5659
searchtitle="click to show/hide search filters bar"
5760
firsttitle="First"
5861
previoustitle="Previous"
@@ -173,6 +176,12 @@ <h2><a href="demo/performance.html">Performance Test</a></h2>
173176
themed.addEventListener('after-copy', function(e) {
174177
table_log('copied one record!');
175178
});
179+
themed.addEventListener('after-move-down', function(e) {
180+
table_log('moved one record down!');
181+
});
182+
themed.addEventListener('after-move-up', function(e) {
183+
table_log('moved one record up!');
184+
});
176185
</script>
177186
</body>
178187
</html>

src/aha-table.html

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717
* <aha-table></aha-table>
1818
*
1919
* <aha-table id="raw"
20-
* selectable="true"
21-
* copyable="true"
22-
* seachable="true"
20+
* selectable
21+
* copyable
22+
* removable
23+
* movable
24+
* seachable
2325
* pagesize="20"
2426
* pagesizetitle="Page Size:"
2527
* summarytitle="Viewing">
2628
* <aha-column name="title"
2729
* type="string"
2830
* label="My Title"
29-
* sortable="true"
30-
* searchable="true"
31-
* required="true"
32-
* editable="false"
33-
* placeholder=""
31+
* sortable
32+
* searchable
33+
* required
34+
* editable
35+
* placeholder="Example text"
3436
* default=""
3537
* hint="Meaning title will help you remember">
3638
* </aha-column>
@@ -43,6 +45,8 @@
4345
* after-create(Object new_record)
4446
* after-copy(Object new_record)
4547
* after-remove(Object removed_record)
48+
* after-move-down(Object moved_record)
49+
* after-move-up(Object moved_record)
4650
*
4751
* @class aha-table
4852
* @author Louis Liu<[email protected]>
@@ -53,9 +57,9 @@
5357
<link rel="import" href="../bower_components/polymer/polymer.html">
5458

5559
<polymer-element name="aha-table" attributes="
56-
selectable searchable copyable removable
60+
selectable searchable copyable removable movable
5761
pagesize data-sizelist
58-
selecttitle selectalltitle sorttitle columntitle copytitle removetitle edittitle searchtitle firsttitle nexttitle previoustitle lasttitle
62+
selecttitle selectalltitle sorttitle columntitle copytitle removetitle movedowntitle moveuptitle edittitle searchtitle firsttitle nexttitle previoustitle lasttitle
5963
pagetext pageoftext pagesizetext summarytext itemoftext
6064
">
6165
<template>
@@ -96,6 +100,8 @@
96100
border-top: 5px solid black;
97101
}
98102
.copy-er,
103+
.move-down-er,
104+
.move-up-er,
99105
.remove-er {
100106
cursor: pointer;
101107
}
@@ -105,6 +111,12 @@
105111
.remove-er i:before {
106112
content: '-';
107113
}
114+
.move-down-er i:before {
115+
content: '\2193';
116+
}
117+
.move-up-er i:before {
118+
content: '\2191';
119+
}
108120
.hint:before {
109121
content: 'i';
110122
}
@@ -222,6 +234,16 @@
222234
title="{{ removetitle }}">
223235
<i></i>
224236
</a>
237+
<a class="move-down-er {{ movable ? '' : 'hide' }}"
238+
on-click="{{movedown}}"
239+
title="{{ movedowntitle }}">
240+
<i></i>
241+
</a>
242+
<a class="move-up-er {{ movable ? '' : 'hide' }}"
243+
on-click="{{moveup}}"
244+
title="{{ moveuptitle }}">
245+
<i></i>
246+
</a>
225247
</td>
226248
<td template
227249
repeat="{{ column in meta }}"
@@ -347,6 +369,8 @@
347369
copyable: false,
348370
//removable: if table row is removable
349371
removable: false,
372+
//movable: if table row is movable
373+
movable: false,
350374
//searchable: if table row is searchable
351375
searchable: false,
352376
// text displayed in first column of search row.
@@ -363,6 +387,10 @@
363387
copytitle: "",
364388
// text displayed as title of remove checkbox..
365389
removetitle: "",
390+
// text displayed as title of move up indicator.
391+
moveuptitle: "",
392+
// text displayed as title of move down indicator.
393+
movedowntitle: "",
366394
// text displayed as title of editable cell.
367395
edittitle: "",
368396
//sortedColumn: sorted column name
@@ -507,6 +535,10 @@
507535

508536
this.refreshPagination();
509537
},
538+
unsort: function() {
539+
this.sortedColumn = "";
540+
this.refreshPagination();
541+
},
510542
search: function(e, p) {
511543
if(e.target.templateInstance.model.column){
512544
var searchedColumn = e.target.templateInstance.model.column.name;
@@ -730,12 +762,46 @@
730762
}
731763
this.fire('after-remove', obj);
732764
},
765+
movedown: function(e) {
766+
var obj = e.target.templateInstance.model.row;
767+
this.fire('before-move-down', obj);
768+
if (this.sortedColumn) {
769+
this.unsort();
770+
}
771+
this.data.movedown(obj);
772+
this.fire('after-move-down', obj);
773+
},
774+
moveup: function(e) {
775+
var obj = e.target.templateInstance.model.row;
776+
this.fire('before-move-up', obj);
777+
if (this.sortedColumn) {
778+
this.unsort();
779+
}
780+
this.data.moveup(obj);
781+
this.fire('after-move-up', obj);
782+
},
733783
toggleFilters: function() {
734784
this.searchable = !this.searchable;
735785
}
736786
});
737787

738788
// Private methods
789+
Array.prototype.moveup = function (obj) {
790+
var index = this.indexOf(obj);
791+
if (index > 0) {
792+
this[index] = this[index-1];
793+
this[index-1] = obj;
794+
}
795+
return this;
796+
}
797+
Array.prototype.movedown = function (obj) {
798+
var index = this.indexOf(obj);
799+
if (index > -1 && index < this.length - 1) {
800+
this[index] = this[index+1];
801+
this[index+1] = obj;
802+
}
803+
return this;
804+
}
739805
</script>
740806
</polymer-element>
741807

@@ -750,11 +816,11 @@
750816
* <aha-column
751817
* name="content"
752818
* type="text"
753-
* sortable="true"
754-
* searchable="true"
755-
* required="true"
756-
* editable="true"
757-
* placeholder=""
819+
* sortable
820+
* searchable
821+
* required
822+
* editable
823+
* placeholder="example"
758824
* default="">
759825
* </aha-column>
760826
*

0 commit comments

Comments
 (0)