Ionic2集成ngx-datatable,ng2-tree第三方控件.md
因为Ionic2中没有DataTable控件,也没有Tree控件,我们这边又要求使用Ionic来开发WebPC端的应用,所以就采用集成第三方的方案,最终选择了ngx-datatable
和ng2-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-datatable
和ng2-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的更多相关文章
- Ionic2中集成第三方控件Sweetalert
Ionic2混合开发,入坑系列:Ionic2中集成第三方控件Sweetalert 注:Sweetalert2已经可以直接从npm中下载安装 npm install --save sweetalert2 ...
- delphi使用 第三方控件
第三方控件安装时必须把所有的pas,dcu,dpk,res等文件复制到你的Lib目录下 然后通过dpk进行安装 安装后会多出来新的控件面板,新控件就在那里了 当然也有一些控件会安装到原有的面板上 比如 ...
- 【转】WPF - 第三方控件
WPF - 第三方控件 目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效 ...
- ActiveReports 报表应用教程 (13)---嵌入第三方控件
葡萄城ActiveReports报表与Visual Studio完美集成,给我们带来更为灵活易用的报表定制和自定义控件嵌入支持,除了可以在报表中使用葡萄城ActiveReports报表内置控件外,您还 ...
- WPF 第三方控件
目前第三方控件在网上形成巨大的共享资源,其中包括收费的也有免费的,有开源的也有不开源的,合理的使用第三方控件将使项目组的工作事半功倍.比如项目中有些复杂的业务逻辑.有些绚丽的效果需要有专门的定制控件才 ...
- WPF第三方控件盘点
WPF统一的编程模型.语言和框架,实现了界面设计人员和开发人员工作可以分离的境界,鉴于WPF强大的优势,且一直是开发者关注的地方,下面和大家分享基于WPF项目开发需要用到的第三方控件,包括业界最受好评 ...
- 好用的第三方控件,Xcode插件(不断更新)
第三方控件类: 1.提示框 MBProgressHUD: 是一款非常强大的.提供多种样式的提示框.使用起来简单.方便.可以在GitHub上查看具体的使用方法. https://github.com ...
- Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子
Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...
- 教程-Delphi第三方控件安装卸载指南
1 只有一个DCU文件的组件.DCU文件是编译好的单元文件,这样的组件是作者不想把源码公布.一般来说,作者必须说明此组件适合Delphi的哪种版本,如果版本不对,在安装时就会出现错误.也正是因为没有源 ...
随机推荐
- CVE-2011-1473 tomcat
Per the bottom of: http://tomcat.apache.org/security-7.html#Not_a_vulnerability_in_Tomcat tweak you ...
- 通过案例快速学会Picasso图片缓存库
picasso是Square公司开源的一个Android图形缓存库,官网地址http://square.github.io/picasso/,可以实现图片下载和缓存功能. 下载地址:ht ...
- EularProject 42:单词解码出来的三角形数
Coded triangle numbers Problem 42 The nth term of the sequence of triangle numbers is given by, tn = ...
- php函数in_array奇怪现象
$k = 0; $fieldArr = array('tt', 'bb'); if ( in_array( $k, $fieldArr)) { echo '1'; } 按理来说,是不会输出1的,可是最 ...
- POJ 3207 Ikki's Story IV - Panda's Trick(2-sat)
POJ 3207 Ikki's Story IV - Panda's Trick id=3207" target="_blank" style=""& ...
- 将 Android* Bullet 物理引擎移植至英特尔® 架构
简单介绍 因为眼下的移动设备上可以使用更高的计算性能.移动游戏如今也可以提供震撼的画面和真实物理(realistic physics). 枪战游戏中的手雷爆炸效果和赛车模拟器中的汽车漂移效果等便是由物 ...
- JNI之——'cl' 不是内部或外部命令,也不是可执行的程序或批处理文件
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46604315 问题的出现: 今天卸载了VS2010,重装vs2008后.发 ...
- POJ1338 & POJ2545 & POJ2591 & POJ2247 找给定规律的数
POJ1338 2545 2591 2247都是一个类型的题目,所以放到一起来总结 POJ1338:Ugly Numbers Time Limit: 1000MS Memory Limit: 10 ...
- rest_framework 分页三种
.分页 a. 分页 看第n页 每页显示n条数据: b. 分页 在某个位置 向后查看多少条数据 c. 加密分页 上一页和下一页 本质:查看 记住页码id的最大值和最小值 通过其来准确扫描 过去的话 会从 ...
- Kali linux 2016.2(Rolling)里Metasploit的口令猜测与嗅探
不多说,直接上干货! 对于发现的系统与文件管理类网络服务,比如Telnet.SSH.FTP等,可以进行弱口令的猜测,以及对明文传输口令的嗅探,从而尝试获取直接通过这些服务进入目标网络的通道. 对于SS ...