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的更多相关文章

  1. JS学习之表格的排序

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. JS实现点击表头表格自动排序(含数字、字符串、日期)

    这篇文章主要介绍了利用JS如何实现点击表头后表格自动排序,其中包含数字排序.字符串排序以及日期格式的排序,文中给出了完整的示例代码,并做了注释,相信大家都能看懂,感兴趣的朋友们一起来看看吧. < ...

  3. 9月6日表格标签(table、行、列、表头)(补)

    一.<table> <table>代表表格标签.   <table></table> 1.width  表示表格宽度,宽度表达方式有像素和百分比两种.网 ...

  4. FineUI第十六天---表格的排序和分页

    表格的排序和分页 1.表格的排序需要: AllowSorting:是否允许排序. SortColumn:当前排序的列ID,当然也可以不设置此属性,而是在后台初始化代码中直接指定默认排序字段. Sort ...

  5. HTML table表格转换为Markdown table表格[转]

    举个栗子,当我想要把这个页面的第一个表格转换成Markdown Table时,怎么做更快,效率更高? 只需简单三步,请看示例: 第一步:复制包含HTML table标签的代码 复制table代码(HT ...

  6. 用python解析word文件(段落篇(paragraph) 表格篇(table) 样式篇(style))

    首先需要安装相应的支持库: 直接在命令行执行pip install python-docx 示例代码如下: import docxfrom docx import Document #导入库 path ...

  7. 表格标签(table、行、列、表头)

    表格标签 一.<table> <table>代表表格标签.   <table></table> 1.width  表示表格宽度,宽度表达方式有像素和百分 ...

  8. 轻量级表格插件Bootstrap Table。拥有强大的支持固定表头、单/复选、排序、分页、搜索及自定义表头等功能。

    Bootstrap Table是轻量级的和功能丰富的以表格的形式显示的数据,支持单选,复选框,排序,分页,显示/隐藏列,固定标题滚动表,响应式设计,Ajax加载JSON数据,点击排序的列,卡片视图等. ...

  9. 最好的Angular2表格控件

    现在市面上有大量的JavaScript数据表格控件,包括开源的第三方的和自产自销的.可以说Wijmo的Flexgrid是目前适应Angular 2的最好的表格控件. Angular 2数据表格基本要求 ...

随机推荐

  1. hbase-0.94 Java API

    Hierarchy For Package org.apache.hadoop.hbase Package Hierarchies: All Packages Class Hierarchy java ...

  2. 6.初探Asynctask

    AsyncTask定义了三种泛型类型 Params,Progress和Result. Params 启动任务执行的输入参数,比如HTTP请求的URL.Progress 后台任务执行的百分比.Resul ...

  3. css-css权威指南学习笔记5

    第六章 文本属性 1.text-indent只能作用于块级元素(如p或inline-block或block后的span/a/i等). 2.text-align只能作用于块级元素(如p或inline-b ...

  4. hdu 1410

    Ref : http://www.clanfei.com/2012/04/772.html 可推出公式: ans=sigma[C(N1-1,i)*0.5^(N1+i)] (0<=i<=N2 ...

  5. fedora22切换用户windows分区不能自动挂载

    新建立一个用户后,然后登陆后,再次登出,登陆原来的账户windows分区不能自动挂载

  6. IndentationError: unindent does not match any outer indentation level

    [problem] 从别处copy过来的python代码经过自己改动后,运行出错 [解决过程] vim file :set list  # cat -A file 也可以 可以看到9-12行的inde ...

  7. linux下压缩,解压缩的方法

    linux zip命令 zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip unzip - ...

  8. 谈谈java开发

    1.不要让未来的决策阻止你现在前进的方向 一步步列出每个步骤,那么对于现在应该专注于做什么,就一目了然了.你也不会浪费   时间去担心应该以后操心的事情. 2.不要让自信诱骗你忘事 当你去学习一个新概 ...

  9. 用类方法------>快速创建一个autorelease的对象,在封装的类方法内部

    在封装的类方法内部,也就是+ (id)personWithName:(NSString *)name andAge:(int)age内部: 创建了一个person对象,并且创建了一个person*类型 ...

  10. Linux的用户及用户组

    一./etc/group下存储当前系统中所有的用户组信息 -Group:   x   : 123  :abc,def,xyz -组名称:组密码占位符:组编号:组中用户名列表 二./etc/gshado ...