AngularJS table 按照表头字段排序功能(升序和降序)
一、表格按照表头排序
<!doctype html>
<html ng-app="a3_4">
<head>
<title>表头排序</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<script src="http://apps.bdimg.com/libs/angular.js/1.2.16/angular.min.js"></script> </head>
<body>
<div ng-controller="c3_4">
<table class="table table-responsive" >
<thead>
<tr>
<th >序号</th>
<th ng-click="title='name';desc=!desc">
姓名
<span>
<i ng-class="{true: 'glyphicon glyphicon-sort-by-attributes', false: 'glyphicon glyphicon-sort-by-attributes-alt'}[(desc == 0)]"></i>
</span>
</th>
<th ng-click="title='sex';desc=!desc">
性别
<span>
<i ng-class="{true: 'glyphicon glyphicon-sort-by-attributes', false: 'glyphicon glyphicon-sort-by-attributes-alt'}[(desc == 0)]"></i>
</span>
</th>
<th ng-click="title='age';desc=!desc">
年龄
<span>
<i ng-class="{true: 'glyphicon glyphicon-sort-by-attributes', false: 'glyphicon glyphicon-sort-by-attributes-alt'}[(desc == 0)]"></i>
</span>
</th>
<th ng-click="title='score';desc=!desc">
分数
<span>
<i ng-class="{true: 'glyphicon glyphicon-sort-by-attributes', false: 'glyphicon glyphicon-sort-by-attributes-alt'}[(desc == 0)]"></i>
</span>
</th>
</tr>
</thead> <tbody>
<tr ng-repeat="stu in data | orderBy : title : desc">
<td>{{$index+1}}</td>
<td>{{stu.name}}</td>
<td>{{stu.sex}}</td>
<td>{{stu.age}}</td>
<td>{{stu.score}}</td>
</tr>
</tbody> </table> </div>
<script type="text/javascript">
var a3_4 = angular.module('a3_4', []);
a3_4.controller('c3_4', ['$scope', function ($scope) {
$scope.bold = "bold";
$scope.title = 'score';
$scope.desc = 0;
$scope.data = [
{ name: "张明明", sex: "女", age: 24, score: 95 },
{ name: "李清思", sex: "女", age: 27, score: 87 },
{ name: "刘小华", sex: "男", age: 28, score: 86 },
{ name: "陈忠忠", sex: "男", age: 23, score: 97 }
]; }])
</script>
</body>
</html>
二、备注
备注:该方法主要是实现了表格按照表头字段进行排序功能,可升序排列,也可以降序排列,默认情况下是升序排列即 $scope.desc = 0情况。
三、运行截图


AngularJS table 按照表头字段排序功能(升序和降序)的更多相关文章
- python 根据两个字段排序, 一个升序, 一个降序
from collections import Counter c = Counter(input()) l=sorted(c.items(), key=lambda s:(-s[], s[])) ] ...
- python-冒泡排序,升序、降序
冒泡排序 这个算法的名字由来是因为越大的元素会经交换慢慢浮'到数列的顶端. 冒泡排序的基本思想:重复走访要排序的数列,一次比较两个元素,如果他们的顺序错误就把他们交换过来,直到没有再需要交换,完成排序 ...
- C语言链表中数组实现数据选择排序,升序、降序功能主要难点
链表排序讲解: head指针指向链表的头结点,是找到整个链表的唯一依据,如果head指针丢失,整个链表就找不到了. head存储的是第一个节点的地址,head->next存储的是第二个节点的地址 ...
- iOS之数组的排序(升序、降序及乱序)
#pragma mark -- 数组排序方法(升序) - (void)arraySortASC{ //数组排序 //定义一个数字数组 NSArray *array = @[@(3),@(4),@(2) ...
- Java排序之升序与降序
以前在学校学排序的时候,总是自己写排序的代码,真正到工作中,直接使用java提供的排序方法,但最近发现行业默认的和学习时有些不一样. 以前总是在进行排序时如果前边的数字和后边数字的差为负则交换两个数字 ...
- java List 排序,升序,降序
import java.util.*; public class EntrySets { public static void main(String[] args) { Map<Object, ...
- 通过orderby关键字,LINQ可以实现升序和降序排序。LINQ还支持次要排序。
通过orderby关键字,LINQ可以实现升序和降序排序.LINQ还支持次要排序. LINQ默认的排序是升序排序,如果你想使用降序排序,就要使用descending关键字. static void M ...
- DataGridView使用技巧十三:点击列头实现升序和降序排序
DataGridView 列有三种排序模式.每一列的排序模式是通过该列的 SortMode 属性指定的,该属性可以设置为以下的 DataGridViewColumnSortMode 枚举值之一. Da ...
- 【转】java comparator 升序、降序、倒序从源码角度理解
原文链接:https://blog.csdn.net/u013066244/article/details/78997869 环境jdk:1.7+ 前言之前我写过关于comparator的理解,但是都 ...
随机推荐
- Python2 指定文件编码格式需要注意的地方
python2 中默认的编码格式是unicode, 开发人员经常需要根据需要,将python文件的编码格式设置为utf-8,我们可以在python文件的第一行进行设置,加入如下代码: # encodi ...
- Java 泛型通配符
package com.waston; import java.util.*; public class Main { public static void main(String[] args) { ...
- Java实时监控类库Metrics
随着系统越来越大,越来越复杂,我们需要在业务方面加上一些监控服务.Metrics作为一款监控指标的度量类库,提供了许多工具帮助开发者来完成自定义的监控工作. 使用Metrics 使用Metrics,只 ...
- tomcat设置默认欢迎页、server.xml配置文件中的标签理解
一:要求:输入网址,不加文件名便可以访问默认页面 (1)项目中只有静态文件 方法:更改tomcat下的conf目录下的web.xml文件,如下图: <welcom-file-list>元素 ...
- Unity 代码编译成dll 更新dll实现热更代码
Unity 代码编译成dll 更新dll实现热更代码 实现流程 代码编译成DLL DLL打包成AssetBundle 加载AssetBundle 加载代码程序集 获取指定类 使用反射赋值 C#代码编译 ...
- POJ 2860
#include<iostream> #define MAXN 20 using namespace std; int a_1[MAXN]; int a_2[MAXN]; int main ...
- POJ 2578
#include<iostream> #include<stdio.h> #include<vector> using namespace std; int mai ...
- the fist blood of java-eclipse 哈哈哈哈 封装的运用
class Student { private int id; public String name; public String sex; private int score ...
- mpvue图片轮播遇到的问题
小程序官方写法: <swiper indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" i ...
- vue框架之自定义组件中使用v-model
通常 vue在html常见表单空间支持v-model双向绑定例如 <input v-model="message" placeholder="edit me&quo ...