@@ -57,19 +57,32 @@ Doo.define(
5757 }
5858 return data
5959 }
60+ getIndex ( row ) {
61+ let idx = this . data . rows . findIndex ( ( item , i ) => {
62+ if ( item . id === row . key ) {
63+ return i
64+ }
65+ } )
66+ return idx
67+ }
6068
6169 delete ( elem ) {
6270 let row = this . getParentRow ( elem )
6371 if ( row ) {
6472 this . tbody . removeChild ( row )
65- this . data . rows [ row . getAttribute ( 'key' ) ] = undefined
73+ let idx = this . getIndex ( row )
74+ if ( idx !== undefined ) {
75+ this . data . rows . splice ( idx , 1 )
76+ }
77+
6678 }
6779 }
6880
6981 run ( ) {
7082 this . clear ( )
7183 this . data . rows = this . buildData ( )
7284 this . renderTable ( )
85+
7386 }
7487
7588 add ( ) {
@@ -83,7 +96,7 @@ Doo.define(
8396 this . renderTable ( )
8497 }
8598
86- update ( e ) {
99+ update ( ) {
87100 for ( let i = 0 , len = this . data . rows . length ; i < len ; i += 10 ) {
88101 this . tbody . childNodes [ i ] . childNodes [ 1 ] . childNodes [ 0 ] . innerText = this . data . rows [ i ] . label += ' !!!'
89102 }
@@ -94,10 +107,15 @@ Doo.define(
94107 this . selectedRow . classList . remove ( 'danger' )
95108 this . selectedRow = undefined
96109 }
97- let row = this . getParentRow ( elem )
110+ this . toggleSelect ( this . getParentRow ( elem ) )
111+ }
112+
113+ toggleSelect ( row ) {
98114 if ( row ) {
99115 row . classList . toggle ( 'danger' )
100- this . selectedRow = row
116+ if ( row . classList . contains ( 'danger' ) ) {
117+ this . selectedRow = row
118+ }
101119 }
102120 }
103121
@@ -138,6 +156,6 @@ Doo.define(
138156 this . swapRows ( )
139157 }
140158 } )
141- }
159+ }
142160 }
143161)
0 commit comments