2.1.10 • Published 6 years ago

ngx-ourpalm-table v2.1.10

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

ngx-ourpalm-table

基于angular5.x、bootstrap的表格控件,支持编程式和声明式列配置

Installation

npm install ngx-ourpalm-table --save

Demo(声明式配置) plnkr

<ourpalm-table [table]="table">
    <ourpalm-table-column [column]="{header: '全选', field: 'checkAll', checkbox: true}"></ourpalm-table-column>
    <ourpalm-table-column [column]="{header: '序号', field: 'number', rownumbers: true}"></ourpalm-table-column>
    <ourpalm-table-column [column]="{header: '姓名', field: 'name'}">
        <ng-template let-data="$row">
            {{data.name}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-column [column]="{header: '年龄', field: 'age'}">
        <ng-template let-row="$row">
            {{row.age}}
        </ng-template>
    </ourpalm-table-column>
</ourpalm-table>
export class AppComponent {

    table: OurpalmTable;

    constructor() {
        this.table = new OurpalmTable({
            loadData: (table: OurpalmTable, callback: (page: Page) => {}) => {
                var start = (table.currentPage - 1) * table.pageSize + 1;
                var end = start + table.pageSize;
                end = end > 86 ? 86 : end;
                //构造服务器假数据
                var rows = [];
                for (; start < end; start++) {
                    rows.push({
                        name: `zhangsan${start}`,
                        age: start,
                        email: `zhangsan${start}@163.com`
                    });
                }

                setTimeout(function () {
                    callback({
                        total: 86,
                        rows: rows
                    });
                }, 300);
            }
        });
    }
}

Demo(编程式配置) plnkr

<ourpalm-table [table]="table"></ourpalm-table>
export class AppComponent {

    table: OurpalmTable;

    constructor() {
        this.table = new OurpalmTable({
            columns: [{
                header: '全选',
                checkbox: true
            }, {
                header: '序号',
                rownumbers: true
            }, {
                header: '姓名',
                field: 'name'
            }, {
                header: '年龄',
                field: 'age'
            }],
            loadData: (table: OurpalmTable, callback: (page: Page) => {}) => {
                var start = (table.currentPage - 1) * table.pageSize + 1;
                var end = start + table.pageSize;
                end = end > 86 ? 86 : end;
                //构造服务器假数据
                var rows = [];
                for (; start < end; start++) {
                    rows.push({
                        name: `zhangsan${start}`,
                        age: start,
                        email: `zhangsan${start}@163.com`
                    });
                }

                setTimeout(function () {
                    callback({
                        total: 86,
                        rows: rows
                    });
                }, 300);
            }
        });
    }
}

Demo(Card View)

<ourpalm-table [table]="table">
    <ourpalm-table-column
            [column]="{header: 'Select', field: 'checkAll', checkbox: true}"></ourpalm-table-column>
    <ourpalm-table-column
            [column]="{header: 'Number', field: 'number', rownumbers: true}"></ourpalm-table-column>
    <ourpalm-table-column [column]="{header: 'ID', field: 'ID'}">
        <ng-template let-row="$row">
            {{row.ID}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-column [column]="{header: 'Price', field: 'Price', sort: true}">
        <ng-template let-row="$row">
            {{row.Price}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-column [column]="{header: 'Cost', field: 'Cost'}">
        <ng-template let-row="$row">
            {{row.Cost}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-column [column]="{header: 'Url', field: 'Url'}">
        <ng-template let-row="$row">
            {{row.Url}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-column [column]="{header: 'Other', field: 'Other'}">
        <ng-template let-row="$row">
            {{row.Other}}
        </ng-template>
    </ourpalm-table-column>
    <ourpalm-table-rowview>
        <ng-template let-row="$row" let-index="$index">
            <div>
                <div style="display:inline-block;float:left;"><img [src]="row.Url"></div>
                <div style="text-align:left;padding-left:10px;display:inline-block;overflow:auto;">
                    <p>ID:{{row.ID}}</p>
                    <p>Price:{{row.Price}}</p>
                    <p>Cost:{{row.Cost}}</p>
                    <p style="overflow:auto">Other:{{row.Other}}</p>
                </div>
            </div>
        </ng-template>
    </ourpalm-table-rowview>
</ourpalm-table>
export class CardViewComponent {

    table: OurpalmTable;

    constructor(private http: Http) {
        this.table = new OurpalmTable({
            rowViewShowType: 'both',
            loadData: (table: OurpalmTable, callback: (page: Page) => {}) => {
                this.http
                    .get('http://rapapi.org/mockjsdata/3828/ngx-ourpalm-table/cardview.do')
                    .map((response) => response.json())
                    .subscribe((result) => {
                        console.log(result);
                        callback({
                            total: result.data.length,
                            rows: result.data
                        });
                    });
            }
        });
    }
}

表属性

属性名属性值类型默认值描述
tableClassstringtable table-bordered table-striped table-hover text-center自定义表格的class
autoLoadDatabooleantrue初始化表格的时候是否自动加载第一页
paginationbooleantrue是否显示分页控件
singleSelectbooleanfalse是否限制只能选中一行
serverSortbooleantrue是否要服务器排序
multiSortbooleantrue是否允许多列排序
pageListarray10,20,30,40,50在设置分页属性的时候 初始化页面大小选择列表
pageSizeint10在设置分页属性的时候初始化页面大小
skipPagebooleantrue在设置分页属性的时候是否允许用户跳转页面
cacheKeystring''客户端存储table信息是对应存放在localStorage中的key
cachePageSizebooleanfalse是否在客户端存储table的页大小,刷新的时候页大小不变,保存在localStorage中,key为${cacheKey}-pageSize
cacheColumnsbooleanfalse是否在客户端存在table的列隐藏信息,刷新的时候列的隐藏信息不变,保存在localStorage中,key为${cacheKey}-columns
pagePositionstringbottom分页条在那里显示可取值 'bottom', 'top', 'both'
showRefreshBtnbooleantrue是否显示刷新按钮
showSettingBtnbooleantrue是否显示设置按钮
checkOnSelectbooleantrue选择CheckBox时级联选中当前行
selectOnCheckbooleantrue选择当前行时级联选中checkbox
ctrlSelectbooleanfalse多选时需要按住ctrl键
rowMenusany[]null右键上下文菜单
rowViewRowViewnull自定义row显示
rowViewShowType'rowView' | 'column' | 'both'rowView自定义行渲染模式

列属性

属性名属性值类型默认值描述
headerstring''表头
fieldstring''字段名称
sortbooleanfalse是否列排序
sortOrderstringnull列排序方向,取值 asc 或 desc 或 null
rownumbersbooleanfalse是否为行号列 1...*
showbooleantrue是否隐藏列
checkboxbooleanfalse是否为多选列
sorterfunctionundefined服务器排序不需要设置,客户端排序需要设置,sorter: (column, row1, row2) => row1[column.field] - row2[column.field]
styler()=>any | any''设置表格cell的样式,styler: (rowIndex, columnIndex, rowData) => return { color: 'red' } or styler: { color: 'red' }
clazzstring''设置表格cell的class
disabledContextMenubooleanfalse是否在当前列上禁用上下文菜单

右键菜单属性

属性名属性值类型默认值描述
textstring''菜单名字
iconClsstring''菜单icon
separatorbooleanfalse分割线
showboolean | ()=>booleantrue是否显示
onclickfunctionfalse点击时触发
submenusany[]null子菜单

方法

方法名参数描述
getDisplayedColumns获取显示的列信息
getDisplayedRows获取显示的行信息
getSelectedRows获取选中的行信息
getCheck edRows获取勾选中的行信息
getSortColumns获取排序的列信息
changeColumnscolumns[]动态修改表的列定义,只支持编程方式,不支持声明式方式
chagePageSizepageSize动态修改表的分页大小
firstPage跳转到第一页
prePage跳转到上一页
nextPage跳转到下一页
lastPage跳转到最后一页
refresh刷新当前页
gotoSkipPagepage:number跳转页 1...最大页
setOptionsoptions:OurpalmTable修改表配置项,修改后将触发加载数据
setPageDatapageData: Page设置当页数据
checkAll勾选当前页中的所有行
uncheckAll取消勾选当前页中的所有行
checkRowindex勾选一行,行索引从0开始,传入行索引
uncheckRowindex取消勾选一行,行索引从0开始,传入行索引
openSetting打开设置列面板

事件

事件名参数描述
onClickRowrowIndex, rowData在用户点击一行的时候触发,参数包括:rowIndex:点击的行的索引值,该索引值从0开始。rowData:对应于点击行的记录。
onDblClickRowrowIndex, rowData在用户双击一行的时候触发,参数包括:rowIndex:点击的行的索引值,该索引值从0开始。rowData:对应于点击行的记录。
onClickCellrowIndex, cellIndex, rowData, column在用户点击一个单元格的时候触发。
onDblClickCellrowIndex, cellIndex, rowData, column在用户双击一个单元格的时候触发。
onHeaderCheckBoxChange选择header中多选框时触发
onRowCheckBoxChangerowData, rowIndex用户选中表格行时触发
trackByFunrowIndex, rowDatangFor tr trackBy

全局配置

@NgModule({
    imports: [
        OurpalmTableModule.forRoot()
    ]
})
export class AppModule {

    constructor(private tableConfig: TableConfig) {
        this.tableConfig.config = {
            pageSize: 50,
            pageList: [50, 100, 200]
        }
    }
}

创建table

@Component({
    selector: 'dynamic-table',
    template: `
        <button (click)="log()">click event test</button>
        <button (click)="changeTable1()">table01</button>
        <button (click)="changeTable2()">table02</button>
        <ourpalm-table [table]="table"></ourpalm-table>
    `
})
export class DynamicTableComponent {

    table: OurpalmTable;

    constructor(private tableConfig: TableConfig) {

        //不继承全局配置
        this.table = new Table({
            cacheKey: 'table01',
            cachePageSize: true,
            cacheColumns: true,
            loadData: () => {
            }
        });

        //继承全局配置
        this.table = this.tableConfig.create({
            cacheKey: 'table01',
            cachePageSize: true,
            cacheColumns: true,
            pagePosition: 'both',
            loadData: () => {
            }
        });

    }
}
2.1.10

6 years ago

2.1.9

6 years ago

2.1.8

6 years ago

2.1.7

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.12

6 years ago

2.0.0

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.2.14

7 years ago

0.2.13

7 years ago

0.2.12

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

7 years ago

0.2.8

7 years ago

0.2.7

7 years ago

0.2.6

7 years ago

0.2.5

7 years ago

0.2.4

7 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.1.53

7 years ago

0.1.52

7 years ago

0.1.51

7 years ago

0.1.50

7 years ago

0.1.49

7 years ago

0.1.48

7 years ago

0.1.47

7 years ago

0.1.46

7 years ago

0.1.45

7 years ago

0.1.44

7 years ago

0.1.43

7 years ago

0.1.42

7 years ago

0.1.41

7 years ago

0.1.40

7 years ago

0.1.39

7 years ago

0.1.38

7 years ago

0.1.37

7 years ago

0.1.36

7 years ago

0.1.35

7 years ago

0.1.34

7 years ago

0.1.33

7 years ago

0.1.32

7 years ago

0.1.31

7 years ago

0.1.30

7 years ago

0.1.29

7 years ago

0.1.28

7 years ago

0.1.27

7 years ago

0.1.26

7 years ago

0.1.25

7 years ago

0.1.24

7 years ago

0.1.23

7 years ago

0.1.22

7 years ago

0.1.21

7 years ago

0.1.20

7 years ago

0.1.19

7 years ago

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago