Angular2表格/可排序/table
Angular2表格
1. 官网下载Angular2开发环境,以及给出的quickstart代码示例demo(地址如下),具体步骤不在详述。
https://github.com/angular/quickstart
2. 更改demo中,index.html,导入的文件,以及组件的位置
System.import('app').catch(function(err){ console.error(err); });
<app>Loading...</app>
3. demo中将app文件夹中文件全部删除
4. app文件夹下,新建main.ts文件
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);
5. app文件夹下,新建app.module.ts文件
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './grid';
@NgModule({
imports: [
BrowserModule,
FormsModule
],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
6. app文件夹下,新建grid.ts文件
import {Component, Input, OnInit} from '@angular/core';
import {Column} from './column';
import {Sorter} from './sorter';
import {GridDemo} from './grid-demo';
@Component({
selector: 'app',
templateUrl: 'app/grid.html'
})
export class AppComponent implements OnInit{
@Input() columns:Array<Column>;
@Input() rows:Array<any>;
@Input() name:string;
sorter = new Sorter();
gridDemo = new GridDemo();
sort(key){
this.sorter.sort(key, this.rows);
}
ngOnInit(){
this.columns= this.gridDemo.getColumns();
this.rows=this.gridDemo.getPeople();
console.log(this.name);
}
}
7. app文件夹下,新建column.ts, sorter.ts, grid-demo.ts文件,分别为:
export class Column{
constructor(public name: string, public descr: string){
}
}
export class Sorter{
direction:number;
key:string;
constructor(){
this.direction = 1;
}
sort(key:string,data:any[]){
if(this.key === key){
this.direction = -this.direction;
}
else{
this.direction = 1;
}
this.key = key;
data.sort((a,b) => {
if(a[key] === b[key]){
return 0;
}
else if(a[key] > b[key]){
return this.direction;
}
else{
return -this.direction;
}
});
}
}
import {Component} from '@angular/core';
import {Column} from './column';
@Component({
template:'<grid name="person grid" [rows]="people" [columns]="columns"></grid>'
})
export class GridDemo {
people: Array<Person>;
columns: Array<Column>;
constructor() {
this.people = this.getPeople();
this.columns = this.getColumns();
}
getPeople(): Array<Person> {
return [
{firstName:'Joe',lastName:'Jackson',age:20},
{firstName:'Peter',lastName:'Smith',age:30},
{firstName:'Jane',lastName:'Doe',age:50},
{firstName:'Tim',lastName:'Smith',age:80}
];
}
getColumns(): Array<Column> {
return [
new Column('firstName','First Name'),
new Column('lastName','Last Name'),
new Column('age','Age')
];
}
}
interface Person {
firstName:string;
lastName:string;
age:number;
}
7. 运行
npm start
8. 结果

Angular2表格/可排序/table的更多相关文章
- JS学习之表格的排序
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JS实现点击表头表格自动排序(含数字、字符串、日期)
这篇文章主要介绍了利用JS如何实现点击表头后表格自动排序,其中包含数字排序.字符串排序以及日期格式的排序,文中给出了完整的示例代码,并做了注释,相信大家都能看懂,感兴趣的朋友们一起来看看吧. < ...
- 9月6日表格标签(table、行、列、表头)(补)
一.<table> <table>代表表格标签. <table></table> 1.width 表示表格宽度,宽度表达方式有像素和百分比两种.网 ...
- FineUI第十六天---表格的排序和分页
表格的排序和分页 1.表格的排序需要: AllowSorting:是否允许排序. SortColumn:当前排序的列ID,当然也可以不设置此属性,而是在后台初始化代码中直接指定默认排序字段. Sort ...
- HTML table表格转换为Markdown table表格[转]
举个栗子,当我想要把这个页面的第一个表格转换成Markdown Table时,怎么做更快,效率更高? 只需简单三步,请看示例: 第一步:复制包含HTML table标签的代码 复制table代码(HT ...
- 用python解析word文件(段落篇(paragraph) 表格篇(table) 样式篇(style))
首先需要安装相应的支持库: 直接在命令行执行pip install python-docx 示例代码如下: import docxfrom docx import Document #导入库 path ...
- 表格标签(table、行、列、表头)
表格标签 一.<table> <table>代表表格标签. <table></table> 1.width 表示表格宽度,宽度表达方式有像素和百分 ...
- 轻量级表格插件Bootstrap Table。拥有强大的支持固定表头、单/复选、排序、分页、搜索及自定义表头等功能。
Bootstrap Table是轻量级的和功能丰富的以表格的形式显示的数据,支持单选,复选框,排序,分页,显示/隐藏列,固定标题滚动表,响应式设计,Ajax加载JSON数据,点击排序的列,卡片视图等. ...
- 最好的Angular2表格控件
现在市面上有大量的JavaScript数据表格控件,包括开源的第三方的和自产自销的.可以说Wijmo的Flexgrid是目前适应Angular 2的最好的表格控件. Angular 2数据表格基本要求 ...
随机推荐
- U盘启动 WinPE系统维护工具 任意安装GHO/WIM/ESD系统映像 无广告专业版
WinPE系统维护工具简介: 1.工具箱基于Windows 8 64位系统制作. 2.强大的DG分区工具专业版4.9.1(DOS版为4.9.0). 3.破解windows密码工具. 4.硬盘.内存检测 ...
- MongoDB系列二
简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个高性能,开源,无模式的文档型数据库,是当前NoSql ...
- Promise deeply lookup
Motivation Consider the following synchronous JavaScript function to read a file and parse it as JSO ...
- sql 从一个库中取某个表的数据导入到另一个库中相同结构的表中
sql 2008 从一个库中把 某个表中的数据导入到另一个库中的具有相同结构的表中 use 库1 go insert into 库1.dbo.表1 select * from 库2.dbo.表1 ...
- 不从SD卡启动树莓派2
本文你可以学到: berryboot使用,kali安装,开挂的MobaXterm,以及关于通过LABEL和UUID挂载的小技巧. 本文默认你有一定Linux基础,同时针对刚入门的水平,因为这是我的折腾 ...
- 20145212&20145204信息安全系统实验五
一.实验步骤 1.阅读理解源码 进入/arm2410cl/exp/basic/07_httpd目录,使用 vim编辑器或其他编辑器阅读理解源代码. 2.编译应用程序 运行 make 产生可执行文件 h ...
- light
Unity5中lightmap的坑 http://blog.csdn.net/langresser_king/article/details/48914901 Unity中光照贴图一二坑及解决办法 h ...
- Java---类加载机制,构造方法,静态变量,(静态)代码块,父类,变量加载顺序
直接上代码: 代码1: public class ConstroctTest { private static ConstroctTest test = new ConstroctTest(); // ...
- Bash 会清空从父进程继承来的 OLDPWD
即便 Bash 没有从父进程继承任何的环境变量,Bash 自己也会创建三个环境变量,分别是: $ env -i bash -c export declare -x OLDPWD declare -x ...
- 以空白符结尾的 alias
网上经常有人问这个问题:为什么我写的 alias 在 sudo 下就不管用了? $ alias 'll=ls -l' $ sudo ll a-private-dir sudo: ll: command ...