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数据表格基本要求 ...
随机推荐
- excel出现错误1327 无效的驱动器
错误描述:错误1327 无效的驱动器 错误程序:excel 2003 这是office安装源的位置被移动造 成的的,大部分时候安装时可能使用了移动硬盘或者在安装后调整了盘符就会造成这个问题.官方的 ...
- 数据结构图文解析之:哈夫曼树与哈夫曼编码详解及C++模板实现
0. 数据结构图文解析系列 数据结构系列文章 数据结构图文解析之:数组.单链表.双链表介绍及C++模板实现 数据结构图文解析之:栈的简介及C++模板实现 数据结构图文解析之:队列详解与C++模板实现 ...
- PHPstorm的数据库功能
PHPstorm真是神器,居然有表.视图.存储过程的功能,非常人性化,建表那叫一个舒服,而且sql语句可以像其他代码一样显示"区域",结构更加清晰.
- Simple Network Management Protocol - SNMP Tutorial
30.9 Simple Network Management Protocol Network management protocols specify communication between t ...
- python3的基础练习题
1. 执行 Python 脚本的两种方式 1)/usr/bin/python3 xx.py 2)python3 xx.py #注xx.py需要在内容里面调用由什么解释器执行 2. 简述位.字节的关系 ...
- shell的一些应用场景
列出每个IP的连接数 netstat -n | awk '/^tcp/{print $5}' | awk -F: '!/^::/{print $1}' | sort | uniq -c | sort ...
- iframe子页面点击按钮,执行父页面的点击事件
iframe 子页面点击.parent 父页面 的id(auth-link-btn)的事件 <a href="javascript:void(0);" onclick=&q ...
- 安卓3D游戏-神奇宝贝防御战
我和同学用unity引擎做的,作为软件工程的大作业. 是一个花费金钱抓怪.控制怪物站位.击杀进攻的敌人获得金钱的类似塔防的安卓游戏. 下载地址:http://pan.baidu.com/s/1gdpH ...
- Java 排序算法实现
package test; import java.util.Scanner; public class JavaSort { public static void quickSort(int a[] ...
- win7提示“User Profile Service服务未能登录”
注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 最近,有个同事打电话告诉我说他的用户名无法登陆到系统,提示“User Profile Service服务未能登录,无法加载用户配置文 ...