1- import { type } from "os" ;
2- import { threadId } from "worker_threads" ;
3-
41class DataGrid {
52 columns : any [ ] ;
63 rows : any [ ] ;
@@ -80,7 +77,6 @@ class DataGrid {
8077 : this . checkedRows . filter ( current_row => current_row . id !== row . id )
8178 }
8279
83- // pagination
8480 switchPage ( ) {
8581 this . rows = this . originalRows . slice ( this . currentPage * this . rowsPerPage , this . currentPage * this . rowsPerPage + this . rowsPerPage )
8682 }
@@ -89,34 +85,25 @@ class DataGrid {
8985 this . columns = this . columns . map ( column => column . name === name ? ( { ...column , show : ! column . show } ) : column )
9086 }
9187
92- // construct new columns object with only the subobjects that have a key show as true
88+ // returns visible columns
9389 getColumns ( ) {
9490 return this . columns . filter ( column => column . show )
9591 }
9692
97- /**
98- * Row dragging methods
99- */
10093 onDragStartRow ( event , row , idx ) {
10194 this . draggingRow = row ;
10295 this . draggingRowIdx = idx ;
10396 }
10497
105- onDragEndRow ( event , row , idx ) {
106- // do nothing
107- }
108-
109- // callback called when user drops a row
11098 onDropRow ( event , row , idx ) {
11199 const chunk = this . rows . splice ( this . draggingRowIdx , 1 )
112100 this . rows . splice ( idx , 0 , chunk [ 0 ] )
113-
114- // remove selected from all rows
115- this . rows . forEach ( row => row . selected = false )
101+ this . resetDraggingRow ( )
116102 }
117103
118- // the event must be prevented for the onDrop method to get called
119104 onDragOverRow ( event , row , idx ) {
105+ if ( this . draggingRowIdx === null ) return ;
106+
120107 this . rows [ idx ] . selected = true
121108 event . preventDefault ( )
122109 }
@@ -125,29 +112,28 @@ class DataGrid {
125112 this . rows [ idx ] . selected = false
126113 }
127114
128- /**
129- * Column dragging methods
130- */
115+ resetDraggingRow ( ) {
116+ this . rows . forEach ( row => row . selected = false )
117+ this . draggingRow = null ;
118+ this . draggingRowIdx = null ;
119+ }
120+
131121 onDragStartColumn ( event , column , idx ) {
132122 this . draggingColumn = column ;
133123 this . draggingColumnIdx = idx ;
134124 }
135125
136- onDragEndColumn ( event , row , idx ) {
137- // do nothing
138- }
139-
140126 // callback called when user drops a column
141127 onDropColumn ( event , column , idx ) {
142128 const chunk = this . columns . splice ( this . draggingColumnIdx , 1 )
143129 this . columns . splice ( idx , 0 , chunk [ 0 ] )
144-
145- // remove selected from all columns
146- this . columns . forEach ( column => column . selected = false )
130+ this . resetDraggingColumn ( )
147131 }
148132
149133 // the event must be prevented for the onDrop method to get called
150134 onDragOverColumn ( event , column , idx ) {
135+ if ( this . draggingColumnIdx === null ) return ;
136+
151137 this . columns [ idx ] . selected = true
152138 event . preventDefault ( )
153139 }
@@ -156,6 +142,12 @@ class DataGrid {
156142 this . columns [ idx ] . selected = false
157143 }
158144
145+ resetDraggingColumn ( ) {
146+ this . columns . forEach ( column => column . selected = false )
147+ this . draggingColumn = null ;
148+ this . draggingColumnIdx = null ;
149+ }
150+
159151 // returns an object that maps column names to column instances
160152 getColumnsObject ( ) {
161153 return this . columns . reduce ( ( obj , column ) => {
0 commit comments