因为Ionic2中没有DataTable控件,也没有Tree控件,我们这边又要求使用Ionic来开发WebPC端的应用,所以就采用集成第三方的方案,最终选择了ngx-datatableng2-tree

1. 基本环境配置

1.1. 命令安装相应的依赖

npm i @swimlane/ngx-datatable --save
npm install --save ng2-tree

1.2. 在Module定义中引入对应Module

首先添加import,保证如下依赖的引入:

import { BrowserModule } from '@angular/platform-browser';
import { TreeModule } from 'ng2-tree';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';

一般情况BrowserModule都是默认存在的,不需要单独引入。

然后在@NgModule装饰器中添加Module引入,保证如下三个Module的存在:

@NgModule({
...
imports: [
...
BrowserModule,
TreeModule,
NgxDatatableModule,
...
],
...
})
export class AppModule { }

1.3. 引入对应的CSS

src/assets下新建文件夹ngx-datatableng2-tree,并复制如下文件:

ngx-datatable下需要的文件:

'{{ROOT}}/node_modules/@swimlane/ngx-datatable/release/themes/*',
'{{ROOT}}/node_modules/@swimlane/ngx-datatable/release/index.css'

ng2-tree下需要的文件:

'{{ROOT}}/node_modules/ng2-tree/styles.css'

并在index.html中增加如下引入:

<link rel="stylesheet" type="text/css" href="assets/ngx-datatable/index.css" />
<link rel="stylesheet" type="text/css" href="assets/ngx-datatable/material.css" />
<link rel="stylesheet" type="text/css" href="assets/ngx-datatable/dark.css" />
<link rel="stylesheet" type="text/css" href="assets/ng2-tree/styles.css" />

2. 简单使用示例验证是否集成成功

2.1. ngx-datatable的使用

官方给出的最简单的实例如下,可以用于验证是否集成成功

import { Component } from '@angular/core';

@Component({
selector: 'app',
template: `
<div>
<ngx-datatable
[rows]="rows"
[columns]="columns">
</ngx-datatable>
</div>
`
})
export class AppComponent {
rows = [
{ name: 'Austin', gender: 'Male', company: 'Swimlane' },
{ name: 'Dany', gender: 'Male', company: 'KFC' },
{ name: 'Molly', gender: 'Female', company: 'Burger King' },
];
columns = [
{ prop: 'name' },
{ name: 'Gender' },
{ name: 'Company' }
];
}

详细的使用参考官方示例,每个实例都可以通多点击标头的Source按钮查看源码。

2.2. ng2-tree的使用

官方给出的实例如下:

import { TreeModel, NodeEvent } from 'ng2-tree';

@Component({
selector: 'myComp',
// 2 - listent for nodeSelected events and handle them
template: `<tree [tree]="tree" (nodeSelected)="logEvent($event)"></tree>`
})
class MyComponent {
public tree: TreeModel = { ... }; // 3 - print caught event to the console
public logEvent(e: NodeEvent): void {
console.log(e);
}
}

其中的TreeModel就是DataModel的定义,如下:

interface TreeModel {
value: string | RenamableNode;
children?: Array<TreeModel>;
loadChildren?: ChildrenLoadingFunction;
settings?: TreeModelSettings;
}

TreeModel具体数据的示例如下:

{
value: 'Programming languages by programming paradigm',
children: [
{
value: 'Object-oriented programming',
children: [
{value: 'Java'},
{value: 'C++'},
{value: 'C#'},
]
},
{
value: 'Prototype-based programming',
children: [
{value: 'JavaScript'},
{value: 'CoffeeScript'},
{value: 'Lua'},
]
}
]
}

详细的使用方式查看官方文档

Ionic2集成ngx-datatable,ng2-tree第三方控件.md的更多相关文章

  1. Ionic2中集成第三方控件Sweetalert

    Ionic2混合开发,入坑系列:Ionic2中集成第三方控件Sweetalert 注:Sweetalert2已经可以直接从npm中下载安装 npm install --save sweetalert2 ...

  2. delphi使用 第三方控件

    第三方控件安装时必须把所有的pas,dcu,dpk,res等文件复制到你的Lib目录下 然后通过dpk进行安装 安装后会多出来新的控件面板,新控件就在那里了 当然也有一些控件会安装到原有的面板上 比如 ...

  3. 【转】WPF - 第三方控件

    WPF - 第三方控件 目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效 ...

  4. ActiveReports 报表应用教程 (13)---嵌入第三方控件

    葡萄城ActiveReports报表与Visual Studio完美集成,给我们带来更为灵活易用的报表定制和自定义控件嵌入支持,除了可以在报表中使用葡萄城ActiveReports报表内置控件外,您还 ...

  5. WPF 第三方控件

    目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效果需要有专门的定制控件才 ...

  6. WPF第三方控件盘点

    WPF统一的编程模型.语言和框架,实现了界面设计人员和开发人员工作可以分离的境界,鉴于WPF强大的优势,且一直是开发者关注的地方,下面和大家分享基于WPF项目开发需要用到的第三方控件,包括业界最受好评 ...

  7. 好用的第三方控件,Xcode插件(不断更新)

    第三方控件类:   1.提示框 MBProgressHUD: 是一款非常强大的.提供多种样式的提示框.使用起来简单.方便.可以在GitHub上查看具体的使用方法. https://github.com ...

  8. Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子

    Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...

  9. 教程-Delphi第三方控件安装卸载指南

    1 只有一个DCU文件的组件.DCU文件是编译好的单元文件,这样的组件是作者不想把源码公布.一般来说,作者必须说明此组件适合Delphi的哪种版本,如果版本不对,在安装时就会出现错误.也正是因为没有源 ...

随机推荐

  1. 再来一波PHP程序员必看书籍

    前言 https://segmentfault.com/a/11... 内列出的是已看过的. 本篇文章内列出的书籍是准备要看或者正在看的,与大家分享. 知识无价,还是建议各位童鞋把更多的资金投入到学习 ...

  2. redis为什么选择单线程工作模型

    1.先说一下为什么出现进程,线程 进程:在计算机发明之初就发现,在输入数据时(I/O速度慢),CPU是空闲的,这样就浪费了CPU资源,为了充分利用CPU资源,发明了进程,在输入程序A的数据时,程序B在 ...

  3. 面向对象设计(OOD)七大原则

    这篇文章我会不停的维护它,它将会越来越长,但它是关于我在面向对象中的一些学习的思考心得.希望对自己对各位都能实用处.     开篇前,说明一下写这篇文章的原因.原因是由于设计模式.由于设计模式里的各种 ...

  4. angularjs 模块化

    <!DOCTYPE HTML> <html ng-app="myApp"> <head> <meta http-equiv="C ...

  5. BsonDocument

    http://api.mongodb.com/csharp/current/html/T_MongoDB_Bson_BsonDocument.htm 如何取出document中的数据 BsonDocu ...

  6. .Net配置虚拟域名

    1.在IIS中配置和地址端口,和名称. 2.在hosts文件中加上地址匹配. 3.重启IIS管理网站. 就可以通过虚拟域名进行访问了.

  7. thinkphp5项目--个人博客(二)

    thinkphp5项目--个人博客(二) 项目地址 fry404006308/personalBlog: personalBloghttps://github.com/fry404006308/per ...

  8. 安卓开发--AsyncTask2

    package com.cnn.imageasyncdemo01; import android.app.Activity; import android.content.Intent; import ...

  9. css常用的阴影

    一.box-shadow: 0 2px 15px 0 rgba(0,0,0,.15)!important 二. box-shadow: 0 2px 6px 0 rgba(0,0,0,.4); 三. . ...

  10. ACM-ICPC 2017 Asia Urumqi(第八场)

    A. Coins Alice and Bob are playing a simple game. They line up a row of nnn identical coins, all wit ...