Disabling orderBy in AngularJS while editing the list

前端 未结 8 702
情歌与酒
情歌与酒 2021-01-07 23:06

After applying orderBy in my list of input boxes if i edit any field it starts sorting immediately and i loose focus. I tried to dug in the angular code and fou

8条回答
  •  天涯浪人
    2021-01-07 23:58

    You can create custom filter and call that only when necessary. Example when you click on 'Grid header' for sorting or after dynamically adding/removing values to array, or simply click of a button(Refresh Grid)

    You need to dependency Inject Angular filter and sort filter

    angular
       .module('MyModule')
       .controller('MyController', ['filterFilter', '$filter', MyContFunc])
    
         function ExpenseSubmitter(funcAngularFilter, funcAngularFilterOrderBy) {
           oCont = this;
           oCont.ArrayOfData = [{
             name: 'RackBar',
             age: 24
           }, {
             name: 'BamaO',
             age: 48
           }];
           oCont.sortOnColumn = 'age';
           oCont.orderBy = false;
           var SearchObj = {
             name: 'Bama'
           };
    
           oCont.RefreshGrid = function() {
             oCont.ArrayOfData = funcAngularFilter(oCont.ArrayOfData, SearchObj);
             oCont.ArrayOfData = funcAngularFilterOrderBy('orderBy')(oCont.ArrayOfData, oCont.sortOnColumn, oCont.orderBy);
       }
     }
    

    and call in HTML something like:

    Age Name
    {{val.age}} {{val.name}}

提交回复
热议问题