168168 </template >
169169 </slot >
170170 </template >
171- <template v-if =" pagination_info && selected_rows_info " >
171+ <template v-if =" selected_rows_info && pagination_info && ( checkbox_rows || rows_selectable ) " >
172172 <slot name =" pagination-selected-rows-separator" >
173173 |
174174 </slot >
175175 </template >
176- <template v-if =" selected_rows_info && checkbox_rows " >
176+ <template v-if =" selected_rows_info && ( checkbox_rows || rows_selectable ) " >
177177 <slot name =" selected-rows-info" :selectedItemsCount =" selectedItemsCount" >
178178 {{selectedItemsCount}} rows selected
179179 </slot >
@@ -503,37 +503,20 @@ export default {
503503 this .sort ();
504504 }
505505 },
506+ isShiftSelection (shiftKey ,rowIndex ){
507+ return (shiftKey == true ) && (this .lastSelectedItemIndex != null ) && (this .lastSelectedItemIndex != rowIndex);
508+ },
506509 handleAddRow (payload ) {
507- if (payload .shiftKey ) {
508- this .handleShiftSelection (payload);
509- return ;
510- }
511-
512510 let row = this .vbt_rows [payload .rowIndex ];
513- this .lastSelectedItemIndex = payload .rowIndex ;
514- this .addSelectedItem (row);
515- this .checkAllRowsSelected ();
516- },
517- handleRemoveRow (payload ) {
518- if (payload .shiftKey ) {
519- this .handleShiftSelection (payload);
520- return ;
511+ if (this .isShiftSelection (payload .shiftKey ,payload .rowIndex )) {
512+ let rows = this .getShiftSelectionRows (payload .rowIndex );
513+ rows .forEach ((_row ) => {this .addSelectedItem (_row)});
514+ } else {
515+ this .addSelectedItem (row);
521516 }
522517
523- let row = this .vbt_rows [payload .rowIndex ];
524- this .removeSelectedItem (row);
525- this .allRowsSelected = false ;
526- },
527- handleShiftSelection (payload ) {
528- let lastSelectedItemIndex = (this .lastSelectedItemIndex != null ) ? this .lastSelectedItemIndex : payload .rowIndex ;
529- let start = Math .min (lastSelectedItemIndex, payload .rowIndex );
530- let end = Math .max (lastSelectedItemIndex, payload .rowIndex );
531- let rows = this .vbt_rows .slice (start,end + 1 );
532- this .unSelectAllItems ();
533- rows .forEach ((_row ) => {this .addSelectedItem (_row)});
534- this .checkAllRowsSelected ();
535- },
536- checkAllRowsSelected () {
518+ this .$emit (' on-select-row' , {" selected_items" : cloneDeep (this .selected_items ) ," selected_item" : row});
519+
537520 let difference = [];
538521
539522 if (this .server_mode && ! this .hasUniqueId ) {
@@ -542,10 +525,31 @@ export default {
542525 difference = differenceBy (this .vbt_rows , this .selected_items , this .uniqueId );
543526 }
544527
545- this .allRowsSelected = difference .length == 0 ;
546- },
528+ if (difference .length == 0 ) {
529+ this .allRowsSelected = true ;
530+ // EventBus.$emit('select-select-all-items-checkbox', "from main");
531+ } else {
532+ this .allRowsSelected = false ;
533+ // EventBus.$emit('unselect-select-all-items-checkbox', "from main");
534+ }
547535
536+ this .lastSelectedItemIndex = payload .rowIndex ;
537+ },
538+ handleRemoveRow (payload ) {
539+ let row = this .vbt_rows [payload .rowIndex ];
540+ if (this .isShiftSelection (payload .shiftKey ,payload .rowIndex )) {
541+ let rows = this .getShiftSelectionRows (payload .rowIndex );
542+ rows .forEach ((_row ) => {this .removeSelectedItem (_row)});
543+ } else {
544+ this .removeSelectedItem (row);
545+ }
546+ this .$emit (' on-unselect-row' , {" selected_items" : cloneDeep (this .selected_items )," unselected_item" : row});
547+ // EventBus.$emit('unselect-select-all-items-checkbox');
548+ this .allRowsSelected = false ;
549+ this .lastSelectedItemIndex = payload .rowIndex ;
550+ },
548551 addSelectedItem (item ) {
552+
549553 let index = - 1 ;
550554 if (this .server_mode && ! this .hasUniqueId ) {
551555 index = findIndex (this .selected_items , (selected_item ) => {return isEqual (selected_item, item)});
@@ -556,8 +560,6 @@ export default {
556560 if (index == - 1 ) {
557561 this .selected_items .push (item);
558562 }
559-
560- this .$emit (' on-select-row' , {" selected_items" : _ .cloneDeep (this .selected_items ) ," selected_item" : item});
561563 },
562564 selectAllItems () {
563565
@@ -599,7 +601,18 @@ export default {
599601 return true ;
600602 }
601603 });
602- this .$emit (' on-unselect-row' , {" selected_items" : _ .cloneDeep (this .selected_items )," unselected_item" : item});
604+ },
605+ getShiftSelectionRows (rowIndex ) {
606+ let start = 0 ;
607+ let end = 0 ;
608+ if (this .lastSelectedItemIndex < rowIndex) {
609+ start = this .lastSelectedItemIndex ;
610+ end = rowIndex + 1 ;
611+ } else if (this .lastSelectedItemIndex > rowIndex) {
612+ start = rowIndex;
613+ end = this .lastSelectedItemIndex + 1 ;
614+ }
615+ return this .vbt_rows .slice (start,end);
603616 },
604617 updateFilter (payload ) {
605618 let event = payload .event ;
0 commit comments