博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
angularjs ng-grid 表格使用
阅读量:6188 次
发布时间:2019-06-21

本文共 6154 字,大约阅读时间需要 20 分钟。

hot3.png

  • Html
  • app.js
// 前台分页控件    app.service("frontPaging", function () {    return {        newInstance : function ($scope) {            $scope.totalServerItems = 0;            $scope.pagingOptions = {                pageSizes: [1,5,20, 50, 100],                pageSize: 20,                currentPage: 1            };            $scope.setRealData = function (realData) {                $scope.realData= realData;            };            $scope.setPagingData = function(data, currentPage, pageSize) {                var realData = data.slice((currentPage - 1) * pageSize, currentPage * pageSize);                $scope.pageData = realData;                $scope.totalServerItems = data.length;                if (!$scope.$$phase) {                    $scope.$apply();                }            };            $scope.getPagedDataAsync = function(currentPage, pageSize) {                var data = $scope.realData;                setTimeout(function() {                    $scope.setPagingData(data, currentPage, pageSize);                }, 100);            };            $scope.$watch('pagingOptions', function(newVal, oldVal) {                if (newVal !== oldVal &&  newVal.pageSize !== oldVal.pageSize) {                    $scope.getPagedDataAsync($scope.pagingOptions.currentPage = 1, $scope.pagingOptions.pageSize);                }                else if (newVal !== oldVal &&  newVal.currentPage !== oldVal.currentPage) {                    $scope.getPagedDataAsync($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize);                }            }, true);            return $scope;        }    }});
  • js
/**     * 初始化前台分页控件     * 注意: $scope.setRealData(data.data.list); (后台返回的list)     * 注意: gridOptions { data: "pageData", (分页数据)     */    frontPaging.newInstance($scope);    // 数据源    $scope.data = [        {"ziydwz_id":"34324","wuzmc":"钢管1","guig":"1mm","hansdj":299.00,"buhsdj":300.00, "shul": 1, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"43424","wuzmc":"钢管2","guig":"1mm","hansdj":299.00,"buhsdj":301.00, "shul": 2, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"5435","wuzmc":"钢管3","guig":"1mm","hansdj":299.00,"buhsdj":302.00, "shul": 1, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"543","wuzmc":"钢管4","guig":"1mm","hansdj":299.00,"buhsdj":303.00, "shul": 4, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"423","wuzmc":"钢管5","guig":"1mm","hansdj":299.00,"buhsdj":304.00, "shul": 7, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"654","wuzmc":"钢管6","guig":"1mm","hansdj":299.00,"buhsdj":305.00, "shul": 5, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"423","wuzmc":"钢管7","guig":"1mm","hansdj":299.00,"buhsdj":306.00, "shul": 8, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"654","wuzmc":"钢管8","guig":"1mm","hansdj":299.00,"buhsdj":305.00, "shul": 5, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"654","wuzmc":"钢管9","guig":"1mm","hansdj":299.00,"buhsdj":305.00, "shul": 5, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"654","wuzmc":"钢管10","guig":"1mm","hansdj":299.00,"buhsdj":305.00, "shul": 5, "hansdjSum":0, "buhsdjSum":0},        {"ziydwz_id":"654","wuzmc":"钢管11","guig":"1mm","hansdj":299.00,"buhsdj":305.00, "shul": 5, "hansdjSum":0, "buhsdjSum":0},    ];    $scope.setRealData($scope.data);    $scope.getPagedDataAsync($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize);           // 用于接受选中列    $scope.mySelections = [];    $scope.gridOptions = angular.extend({}, $rootScope.gridOptions, {        data: "pageData",        selectedItems:$scope.mySelections,        useExternalPagination: true,//是否使用分页按钮        enableRowHeaderSelection : true, //是否显示选中checkbox框 ,默认为true        enableFooterTotalSelected: true, // 是否显示选中的总数,默认为true, 如果显示,showGridFooter 必须为true        enableFullRowSelection : true, //是否点击行任意位置后选中,默认为false,当为true时,checkbox可以显示但是不可选中        enableRowSelection : true, // 行选择是否可用,默认为true;        enableCellSelection: true,        enableSelectAll : true, // 选择所有checkbox是否可用,默认为true;        enableSelectionBatchEvent : true, //默认true        selectWithCheckboxOnly: true,        showSelectionCheckbox: true,        CheckBoxHeaderColumn:true,        pagingOptions: $scope.pagingOptions,        filterOptions: $scope.filterOptions,        columnDefs: [            {                field: "wuzmc",                displayName: "商品信息",                width:280,                sortable:false,                pinnable: true,                EnableCheckBoxSelect:true,                enableCellEdit: false            }, {                field: "guig",                displayName: "规格",                width: 120,                sortable: true            }, {                field: "hansdj",                displayName: "单价(含税)",                width: 150,                sortable: true,                enableSorting: true,                cellTemplate:'
¥{
{row.getProperty(col.field)}}
' }, { field: "buhsdj", displayName: "单价(不含税)", width: 150, sortable: true, cellTemplate:'
¥{
{row.getProperty(col.field)}}
' }, { field: "shul", displayName: "数量", width: 200, sortable: false },{ field: "hansdjSum", displayName: "小计(含税)", width: 125, sortable: true, cellTemplate: '
¥{
{row.getProperty(col.field)}}
' },{ field: "buhsdjSum", displayName: "小计(不含税)", width: 125, sortable: true, cellTemplate: '
¥{
{row.getProperty(col.field)}}
' }], totalServerItems: 'totalServerItems', enablePaging: true, showFooter: true }); // 监控 $scope.$watch("mySelections", function() { //console.log($scope.mySelections); if($scope.mySelections.length == 0){ $scope.gouwc.pic = 0; } $scope.choicePicSumRadio(); }, true);

转载于:https://my.oschina.net/u/2489726/blog/837886

你可能感兴趣的文章
阿里云爬虫风险管理产品商业化,为云端流量保驾护航
查看>>
221. Maximal Square
查看>>
一个6年java程序员的工作感悟,写给还在迷茫的你
查看>>
re模块与正则表达式
查看>>
Windows 下的 electron 开发笔记一
查看>>
Java高并发架构设计
查看>>
zookeeper
查看>>
JMS系列(三)-java操作JMS Topic实例
查看>>
[基础篇]PHP引用变量
查看>>
27 Remove Element
查看>>
Go Slice 高级实践
查看>>
从零开始实现一个简易的Java MVC框架(四)--实现AOP
查看>>
精读《手写 SQL 编译器 - 回溯》
查看>>
前端技术周刊 2018-08-06:ES Module
查看>>
JavaScript学习第八天笔记(Function)
查看>>
Laravel 5.4 首次搭建,从 clone 到运行成功
查看>>
电子邮件.NET控件MailBee.NET Objects使用指南合集(上)
查看>>
leetcode 258. Add Digits
查看>>
九天学会Java,第三天,选择结构
查看>>
微信小程序开发的完整人性化版攻略
查看>>