table.html 2.67 KB
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8" />
    <title></title>
</head>

<body>
    <div ng-app="esNgAntd" ng-controller="mainCtrl">
        <div class="container" style="padding: 50px">
                <es-table columns="columns" d-source="dataSource" row-selection="rowSelection" loading="{{loading}}" on-change="handleChange(sorter)" size="small"/>
        </div>
    </div>
    <script src="https://cdn.staticfile.org/angular.js/1.2.28/angular.min.js"></script>
    <script src="../dist/ng-antd.js"></script>
    <script>
        angular
            .module("esNgAntd")
            .controller("mainCtrl", function ($scope, $timeout) {
                $scope.loading = false;

                $scope.columns = [
                    {
                        title: "批次",
                        key: "name",
                        width: "100px",
                    },
                    {
                        title: "航线",
                        key: "age",
                        sorter: true,
                        sortOrder: "ascend"
                    },
                    {
                        title: "状态",
                        key: "status",
                    },
                    {
                        title: "操作",
                        key: "action",
                        render: (value, record, index) => {
                            return `<a ng-click="handleClick(${index})">Delete</a>`;
                        }
                    },
                ];

                $scope.dataSource = [
                    {
                        id: 1,
                        name: "AAA",
                        age: 32,
                        status: 1,
                    },
                    {
                        id: 2,
                        name: "BBB",
                        age: 42,
                        status: 0,
                    },
                ];

                $scope.rowSelection = {
                    onChange: (selectedRowKeys, selectedRows) => {
                        // console.log(selectedRowKeys, selectedRows);
                    },
                    getCheckboxProps: (record) => ({
                        disabled: record.age === 42,
                    }),
                };

                $scope.handleChange = (sorter) => {
                    console.log(sorter);
                };

                $scope.handleClick = (key) => {
                    $scope.dataSource[key].status = $scope.dataSource[key].status ? 0 : 1;
                    $scope.dataSource.splice(key, 1);
                    console.log($scope.dataSource);
                };
            });
    </script>
</body>

</html>