简体   繁体   English

angularJS不显示行,具体取决于NG网格中的值

[英]angularJS Do Not Display A Row Depending On Value In An NG-Grid

I am new to angularJS ad I have been asked to hide a row in my ng-grid table if a value of a column is '0'. 我是angularJS广告的新手,如果一列的值为'0',我被要求在ng-grid表中隐藏一行。

My grid has 4 columns: 我的grid有4列:

  • User 用户
  • Today 今天
  • This Week 本星期
  • This Month 这个月

And I want to hide an entire row if 'This Month' column is '0' 如果“本月”列为“ 0”,我想隐藏整行

My HTML for the gird is: 我的gird HTML是:

<div data-ng-controller="workflowworkitemscompleted as vm">
    <div data-ng-if="isbusy">
        <div data-cc-spinner="vm.spinnerOptions"></div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="gridStyle" style="height:157px" data-ng-grid="gridOptions" id="cwigrid"></div>
        </div>
    </div>
</div>

My controller code is: 我的控制器代码是:

$scope.searchfilter = "";
    $scope.mySelections = [];
    $scope.sortInfo = { fields: ['countDay'], directions: ['desc'] };
    $scope.totalServerItems = 0;
    $scope.pagingOptions = {
        pageSizes: [5],
        pageSize: 5,
        currentPage: 1
    };

    $scope.gridOptions = {
        data: 'wfiprocessed',
        multiSelect: false,
        rowHeight: 25,
        showFooter: false,
        footerRowHeight: 40,
        enableColumnReordering: false,
        showColumnMenu: false,
        enableColumnResize: false,
        enableRowSelection: false,
        filterOptions: $scope.filterOptions,
        selectedItems: $scope.mySelections,
        enablePaging: false,
        pagingOptions: $scope.pagingOptions,
        plugins: [gridLayoutPlugin],
        totalServerItems: 'totalServerItems',
        sortInfo: $scope.sortInfo,
        useExternalSorting: false,
        virtualizationThreshold: 50,
        rowTemplate: "<div ng-style=\"{ 'cursor': row.cursor }\" ng-repeat=\"col in renderedColumns\" class=\"ngCell {{col.colIndex()}} {{col.cellClass}}\">" +
            "   <div class=\"ngVerticalBar\" ng-style=\"{height: rowHeight}\" ng-class=\"{ ngVerticalBarVisible: !$last }\">&nbsp;</div>" +
            "   <div ng-cell></div>" +
            "</div>",
        columnDefs: [
            { field: 'userName', displayName: 'User', cellTemplate: vm.optimizedcell },
            { field: 'countDay', displayName: 'Today', cellTemplate: vm.optimizedcell },
            { field: 'countWeek', displayName: 'This Week', cellTemplate: vm.optimizedcell },
            { field: 'countMonth', displayName: 'This Month', cellTemplate: vm.optimizedcell }
        ]
    };

And my table looks like: 我的桌子看起来像: 在此处输入图片说明

Looking at the table above, I don't want the 'dtealdev' or 'qauser2' rows to be displayed as the 'This Month' column is '0' 查看上表,我不希望由于“本月”列为“ 0”而显示“ dtealdev”或“ qauser2”行

In your data source of $scope.gridOptions you feed all the dataset you want to show in the grid. $scope.gridOptions数据源中, $scope.gridOptions要显示在网格中的所有数据集。 What you are doing is, you are passing the undesirable field ie, qauser2 and dtealedev in this data set too. 您正在做的是,您也在此数据集中传递了不想要的字段,即qauser2dtealedev

What you can do is return only the desired set of data values that need to show. 您可以做的是仅返回需要显示的一组所需的数据值。

$scope.gridOptions.data = function(data) {
    //remove the items in data that contain 0 in all fields

    return newData;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM