@@ -167,8 +167,7 @@ define([
167
167
* Sets record data to cache
168
168
*/
169
169
setRecordDataToCache : function ( data ) {
170
- this . recordDataCache = this . recordDataCache && data . length > this . recordDataCache . length ?
171
- data : this . recordDataCache ;
170
+ this . recordDataCache = data ;
172
171
} ,
173
172
174
173
/**
@@ -270,10 +269,12 @@ define([
270
269
* @param {Number|String } id
271
270
*/
272
271
deleteHandler : function ( index , id ) {
272
+ var defaultState ;
273
273
this . setDefaultState ( ) ;
274
+ defaultState = this . defaultPagesState [ this . currentPage ( ) ] ;
274
275
this . processingDeleteRecord ( index , id ) ;
275
276
this . pagesChanged [ this . currentPage ( ) ] =
276
- ! compareArrays ( this . defaultPagesState [ this . currentPage ( ) ] , this . arrayFilter ( this . getChildItems ( ) ) ) ;
277
+ ! compareArrays ( defaultState , this . arrayFilter ( this . getChildItems ( ) ) ) ;
277
278
this . changed ( _ . some ( this . pagesChanged ) ) ;
278
279
} ,
279
280
@@ -327,7 +328,7 @@ define([
327
328
} ,
328
329
329
330
/**
330
- * Set default dynamic-rows state
331
+ * Set default dynamic-rows state or state before changing data
331
332
*
332
333
* @param {Array } data - defaultState data
333
334
*/
@@ -625,6 +626,19 @@ define([
625
626
this . pages ( pages ) ;
626
627
} ,
627
628
629
+ /**
630
+ * Reinit record data in order to remove deleted values
631
+ *
632
+ * @return void
633
+ */
634
+ reinitRecordData : function ( ) {
635
+ this . recordData (
636
+ _ . filter ( this . recordData ( ) , function ( elem ) {
637
+ return elem && elem [ this . deleteProperty ] !== this . deleteValue ;
638
+ } , this )
639
+ ) ;
640
+ } ,
641
+
628
642
/**
629
643
* Get items to rendering on current page
630
644
*
@@ -633,7 +647,6 @@ define([
633
647
getChildItems : function ( data , page ) {
634
648
var dataRecord = data || this . relatedData ,
635
649
startIndex ;
636
-
637
650
this . startIndex = ( ~ ~ this . currentPage ( ) - 1 ) * this . pageSize ;
638
651
639
652
startIndex = page || this . startIndex ;
@@ -672,9 +685,8 @@ define([
672
685
this . bubble ( 'addChild' , false ) ;
673
686
674
687
if ( this . relatedData . length && this . relatedData . length % this . pageSize === 0 ) {
675
- this . clear ( ) ;
676
688
this . pages ( this . pages ( ) + 1 ) ;
677
- this . currentPage ( this . pages ( ) ) ;
689
+ this . nextPage ( ) ;
678
690
} else if ( ~ ~ this . currentPage ( ) !== this . pages ( ) ) {
679
691
this . currentPage ( this . pages ( ) ) ;
680
692
}
@@ -690,11 +702,6 @@ define([
690
702
*/
691
703
processingDeleteRecord : function ( index , recordId ) {
692
704
this . deleteRecord ( index , recordId ) ;
693
-
694
- if ( this . getChildItems ( ) . length <= 0 && this . pages ( ) !== 1 ) {
695
- this . pages ( this . pages ( ) - 1 ) ;
696
- this . currentPage ( this . pages ( ) ) ;
697
- }
698
705
} ,
699
706
700
707
/**
@@ -717,8 +724,8 @@ define([
717
724
return false ;
718
725
}
719
726
720
- this . clear ( ) ;
721
727
this . initChildren ( ) ;
728
+ return true ;
722
729
} ,
723
730
724
731
/**
@@ -743,13 +750,15 @@ define([
743
750
* Change page to next
744
751
*/
745
752
nextPage : function ( ) {
753
+ this . clear ( ) ;
746
754
this . currentPage ( this . currentPage ( ) + 1 ) ;
747
755
} ,
748
756
749
757
/**
750
758
* Change page to previous
751
759
*/
752
760
previousPage : function ( ) {
761
+ this . clear ( ) ;
753
762
this . currentPage ( this . currentPage ( ) - 1 ) ;
754
763
} ,
755
764
@@ -827,24 +836,21 @@ define([
827
836
deleteRecord : function ( index , recordId ) {
828
837
var recordInstance ,
829
838
lastRecord ,
830
- recordsData ,
831
- childs ;
839
+ recordsData ;
832
840
833
841
if ( this . deleteProperty ) {
842
+ recordsData = this . recordData ( ) ;
834
843
recordInstance = _ . find ( this . elems ( ) , function ( elem ) {
835
844
return elem . index === index ;
836
845
} ) ;
837
846
recordInstance . destroy ( ) ;
838
847
this . elems ( [ ] ) ;
839
848
this . _updateCollection ( ) ;
840
849
this . removeMaxPosition ( ) ;
841
- this . recordData ( ) [ recordInstance . index ] [ this . deleteProperty ] = this . deleteValue ;
842
- this . recordData . valueHasMutated ( ) ;
843
- childs = this . getChildItems ( ) ;
844
-
845
- if ( childs . length > this . elems ( ) . length ) {
846
- this . addChild ( false , childs [ childs . length - 1 ] [ this . identificationProperty ] , false ) ;
847
- }
850
+ recordsData [ recordInstance . index ] [ this . deleteProperty ] = this . deleteValue ;
851
+ this . recordData ( recordsData ) ;
852
+ this . reinitRecordData ( ) ;
853
+ this . reload ( ) ;
848
854
} else {
849
855
this . update = true ;
850
856
@@ -866,11 +872,14 @@ define([
866
872
this . update = false ;
867
873
}
868
874
875
+ this . _reducePages ( ) ;
876
+ this . _sort ( ) ;
877
+ } ,
878
+
879
+ _reducePages : function ( ) {
869
880
if ( this . pages ( ) < ~ ~ this . currentPage ( ) ) {
870
881
this . currentPage ( this . pages ( ) ) ;
871
882
}
872
-
873
- this . _sort ( ) ;
874
883
} ,
875
884
876
885
/**
0 commit comments