@@ -203,21 +203,25 @@ var __meta__ = { // jshint ignore:line
203203 var that = this ;
204204 var items = dataItems && dataItems . length ? dataItems : [ dataItems ] ;
205205 var itemsLength = items . length ;
206+ var list = that . _getList ( ) ;
206207 var i ;
207208
208209 that . _unbindDataSource ( ) ;
210+ that . _unbindDataChange ( ) ;
209211 for ( i = 0 ; i < itemsLength ; i ++ ) {
210- that . _addItem ( items [ i ] ) ;
212+ that . _addItem ( items [ i ] , list ) ;
211213 }
214+ that . _bindDataChange ( ) ;
212215 that . _bindDataSource ( ) ;
213216 that . _syncElement ( ) ;
214217 } ,
215218
216- _addItem : function ( dataItem ) {
219+ _addItem : function ( dataItem , list ) {
217220 var that = this ;
218221 var item = that . templates . itemTemplate ( { item : dataItem , r : that . templates . itemContent } ) ;
219222
220- $ ( item ) . attr ( kendoAttr ( UNIQUE_ID ) , dataItem . uid ) . appendTo ( that . _getList ( ) ) ;
223+ $ ( item ) . attr ( kendoAttr ( UNIQUE_ID ) , dataItem . uid ) . appendTo ( list ) ;
224+
221225 if ( typeof dataItem === typeof "" ) {
222226 that . dataSource . _data . push ( dataItem ) ;
223227 } else {
@@ -729,9 +733,11 @@ var __meta__ = { // jshint ignore:line
729733 var i ;
730734
731735 that . _unbindDataSource ( ) ;
736+ that . _unbindDataChange ( ) ;
732737 for ( i = 0 ; i < itemsLength ; i ++ ) {
733738 that . _removeItem ( $ ( listItems [ i ] ) ) ;
734739 }
740+ that . _bindDataChange ( ) ;
735741 that . _bindDataSource ( ) ;
736742 that . _syncElement ( ) ;
737743 that . _updateToolbar ( ) ;
@@ -879,6 +885,21 @@ var __meta__ = { // jshint ignore:line
879885 }
880886 } ,
881887
888+ _bindDataChange : function ( ) {
889+ var dataSource = this . dataSource ;
890+ if ( dataSource . _data && dataSource . _changeHandler ) {
891+ dataSource . _data . bind ( CHANGE , dataSource . _changeHandler ) ;
892+ dataSource . _data . trigger ( CHANGE ) ;
893+ }
894+ } ,
895+
896+ _unbindDataChange : function ( ) {
897+ var dataSource = this . dataSource ;
898+ if ( dataSource . _data && dataSource . _changeHandler ) {
899+ dataSource . _data . unbind ( CHANGE , dataSource . _changeHandler ) ;
900+ }
901+ } ,
902+
882903 _bindDataSource : function ( ) {
883904 var that = this ;
884905 var dataSource = that . dataSource ;
@@ -1287,14 +1308,19 @@ var __meta__ = { // jshint ignore:line
12871308 } ,
12881309
12891310 getUpdatedSelection : function ( items ) {
1311+
1312+ if ( items . length !== 1 ) {
1313+ return null ;
1314+ }
1315+
12901316 var that = this ;
12911317 var itemFilter = that . options . filter ;
12921318 var sourceListBox = that . getSourceListBox ( ) ;
12931319 var lastEnabledItem = sourceListBox ? sourceListBox . items ( ) . filter ( itemFilter ) . last ( ) : null ;
12941320 var containsLastItem = $ ( items ) . filter ( lastEnabledItem ) . length > 0 ;
12951321 var itemToSelect = containsLastItem ? $ ( items ) . prevAll ( itemFilter ) [ 0 ] : $ ( items ) . nextAll ( itemFilter ) [ 0 ] ;
12961322
1297- if ( $ ( items ) . length === 1 && itemToSelect ) {
1323+ if ( itemToSelect ) {
12981324 return itemToSelect ;
12991325 } else {
13001326 return null ;
@@ -1364,7 +1390,7 @@ var __meta__ = { // jshint ignore:line
13641390 canExecute : function ( ) {
13651391 var sourceListBox = this . getSourceListBox ( ) ;
13661392
1367- return ( sourceListBox ? sourceListBox . items ( ) . filter ( ENABLED_ITEM_SELECTOR ) . length > 0 : false ) ;
1393+ return ( sourceListBox ? sourceListBox . wrapper . find ( ENABLED_ITEMS_SELECTOR ) . length > 0 : false ) ;
13681394 } ,
13691395
13701396 getItems : function ( ) {
@@ -1381,7 +1407,7 @@ var __meta__ = { // jshint ignore:line
13811407 canExecute : function ( ) {
13821408 var sourceListBox = this . getSourceListBox ( ) ;
13831409
1384- return ( sourceListBox ? sourceListBox . items ( ) . filter ( ENABLED_ITEM_SELECTOR ) . length > 0 : false ) ;
1410+ return ( sourceListBox ? sourceListBox . wrapper . find ( ENABLED_ITEMS_SELECTOR ) . length > 0 : false ) ;
13851411 } ,
13861412
13871413 getItems : function ( ) {
@@ -1496,13 +1522,14 @@ var __meta__ = { // jshint ignore:line
14961522 _updateToolState : function ( toolName ) {
14971523 var that = this ;
14981524 var command = CommandFactory . current . create ( toolName , { listBox : that . listBox } ) ;
1499- var toolElement = that . element . find ( "[data-command='" + toolName + "']" ) [ 0 ] ;
1525+ var tool = that . element . find ( "[data-command='" + toolName + "']" ) ;
1526+ var toolElement = tool [ 0 ] ;
15001527
15011528 if ( toolElement && command && command . canExecute ) {
15021529 if ( command . canExecute ( ) ) {
1503- $ ( toolElement ) . removeClass ( DISABLED_STATE_CLASS ) . removeAttr ( TABINDEX ) ;
1530+ tool . removeClass ( DISABLED_STATE_CLASS ) . removeAttr ( TABINDEX ) ;
15041531 } else {
1505- $ ( toolElement ) . addClass ( DISABLED_STATE_CLASS ) . attr ( TABINDEX , "-1" ) ;
1532+ tool . addClass ( DISABLED_STATE_CLASS ) . attr ( TABINDEX , "-1" ) ;
15061533 }
15071534 }
15081535 }
0 commit comments