Home Web Front-end JS Tutorial Detailed example of Angular implementing more complex table filtering and deletion functions

Detailed example of Angular implementing more complex table filtering and deletion functions

Dec 23, 2017 pm 03:59 PM
angular accomplish

This article mainly introduces Angular's implementation of more complex table filtering and deletion functions, and analyzes AngularJS's related operating techniques for table sorting, query matching, dynamic modification of page element attributes, etc. in the form of examples. Friends in need can refer to No Hope Can help everyone.

The example in this article describes Angular's implementation of more complex table filtering and deletion functions. Share it with everyone for your reference, the details are as follows:

Let’s take a look at the running effect first:

The specific code is as follows:


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

<!DOCTYPE html>

<html>

  <head>

    <meta charset="utf-8" />

    <title>www.jb51.net Angular过滤、删除</title>

    <style>

      table{

        border: 1px solid black;

        width: 800px;

      }

      td , th{

        border: 1px solid black;

        text-align: center;

      }

      th{

        background: #767674;

      }

      .d1{

        width: 50%;

        margin: 0 auto;

      }

      .d2{

        margin-top: 10px;

      }

      .btn{

        background: green;

        color: white;

      }

      .btn1{

        background: red;

        color: white;

      }

      tr:nth-child(2n){

        background-color: gainsboro;

      }

    </style>

    <script src="angular.min.js"></script>

    <script type="text/javascript" src="jquery-1.9.1.min.js" ></script>

    <script>

      angular.module("MyApp",[])

      .controller("democ",function($scope,$filter){

        $scope.isc = false;

        $scope.arrs = [{

                checked:false,

                id:7,

                name:"OPPO R9s",

                user:"赵云",

                tel:15777777777,

                price:4999,

                city:"北京",

                time:new Date(&#39;03-09 10:00&#39;),

                sta:"已发货"

               },

               {

                checked:false,

                id:12,

                name:"VIVO X20",

                user:"关羽",

                tel:15333333333,

                price:2998,

                city:"上海",

                time:new Date(&#39;08-22 10:00&#39;),

                sta:"已发货"

               },

               {

                checked:false,

                id:1,

                name:"iPhone 8 Plus",

                user:"曹操",

                tel:15111111111,

                price:7588,

                city:"北京",

                time:new Date(&#39;09-04 10:00&#39;),

                sta:"已发货"

               },

               {

                checked:false,

                id:11,

                name:"小*Note5",

                user:"黄忠",

                tel:13222222222,

                price:699,

                city:"重庆",

                time:new Date(&#39;02-28 10:00&#39;),

                sta:"发货"

               },

               {

                checked:false,

                id:1,

                name:"小*Mix2",

                user:"黄盖",

                tel:13111111111,

                price:3299,

                city:"北京",

                time:new Date(&#39;03-015 10:00&#39;),

                sta:"发货"

               }];

               $scope.arr = $scope.arrs;

               $scope.seluser = function(){

                 $scope.arr = [];

                 var val = $scope.reg_user;

                 var f = $filter("filter");

                 $scope.arr = f($scope.arrs,{"user":val});

               }

               $scope.seltel = function(){

                 $scope.arr = [];

                 var val = $scope.reg_tel;

                 var f = $filter("filter");

                 $scope.arr = f($scope.arrs,{"tel":val});

               }

               $scope.selsta = function(){

                $scope.arr = [];

                var val = $scope.reg_sta;

                var f = $filter("filter");

                $scope.arr = f($scope.arrs,{"sta":val});

               }

               $scope.ckAll = function(){

                var ck = $scope.sta_ck;

                for(var i=0; i<$scope.arrs.length; i++){

                  $scope.arrs[i].checked = ck;

                }

               }

               $scope.del = function(th){

                $scope.arrs.splice(th,1);

               }

               $scope.delAll = function(){

                for(var i=0; i<$scope.arrs.length; i++){

                  if($scope.arrs[i].checked==true){

                    $scope.arrs.splice(i,1);

                    i--;

                  }

                }

               }

               $scope.add = function(){

                var d=new Date();

                $scope.arrs.push({

                  checked:false,

                  id:$scope.a_id,

                  name:$scope.a_name,

                  user:$scope.a_user,

                  tel:$scope.a_tel,

                  price:$scope.a_price,

                  city:$scope.a_city,

                  time:d,

                  sta:"发货"

                });

                $scope.arr = $scope.arrs;

                $scope.isc = false;

               }

      });

    </script>

  </head>

<body ng-app="MyApp" ng-controller="democ">

    <p class="d1">

      <p>

        <input type="text" placeholder="用户名搜索" ng-change="seluser()" ng-model="reg_user"/>

        <input type="text" placeholder="手机号搜索" ng-change="seltel()" ng-model="reg_tel"/>

        <select>

          <option>选择城市</option>

          <option>北京</option>

          <option>上海</option>

          <option>广州</option>

        </select>

        <select ng-change="selsta()" ng-model="reg_sta">

          <option value="">选择状态</option>

          <option value="发货">发货</option>

          <option value="已发货">已发货</option>

        </select>

        <select ng-model="selid">

          <option value="">--请选择--</option>

          <option value="id">ID正序</option>

          <option value="-id">ID倒叙</option>

        </select>

        <select ng-model="selmonth">

          <option value="">开始月份</option>

          <option value="1">1</option>

          <option value="2">2</option>

          <option value="3">3</option>

          <option value="4">4</option>

          <option value="5">5</option>

          <option value="6">6</option>

          <option value="7">7</option>

          <option value="8">8</option>

          <option value="9">9</option>

          <option value="10">10</option>

          <option value="11">11</option>

          <option value="12">12</option>

        </select>

        <select ng-model="lastmonth">

          <option value="">结束月份</option>

          <option value="1">1</option>

          <option value="2">2</option>

          <option value="3">3</option>

          <option value="4">4</option>

          <option value="5">5</option>

          <option value="6">6</option>

          <option value="7">7</option>

          <option value="8">8</option>

          <option value="9">9</option>

          <option value="10">10</option>

          <option value="11">11</option>

          <option value="12">12</option>

        </select>

      </p>

      <p class="d2">

        <input type="button" value="新增订单" class="btn" ng-click="isc=true"/>

        <input type="button" value="批量发货" class="btn"/>

        <input type="button" value="批量删除" class="btn1" ng-click="delAll()"/>

        敏感词:米(商品名)->替换成*

      </p>

      <p>

        <table cellpadding="0" cellspacing="0">

          <tr>

            <th><input type="checkbox" ng-change="ckAll()" ng-model="sta_ck"/></th>

            <th>ID</th>

            <th>商品名</th>

            <th>用户名</th>

            <th>手机号</th>

            <th>价格</th>

            <th>城市</th>

            <th>下单时间</th>

            <th>状态</th>

            <th>操作</th>

          </tr>

          <tr ng-repeat="a in arr|orderBy : selid | filter:{time:selmonth} | filter:{time:lastmonth}">

            <td><input type="checkbox" ng-model="a.checked"/></td>

            <td>{{a.id}}</td>

            <td>{{a.name}}</td>

            <td>{{a.user}}</td>

            <td>{{a.tel}}</td>

            <td>{{a.price|currency : &#39;¥&#39;}}</td>

            <td>{{a.city}}</td>

            <td>{{a.time|date : &#39;MM-HH hh:dd:ss&#39;}}</td>

            <td>

              <span ng-show="a.sta==&#39;已发货&#39;">{{a.sta}}</span>

              <span ng-show="a.sta==&#39;发货&#39;"><a href="#" rel="external nofollow" ng-click="a.sta=&#39;已发货&#39;">{{a.sta}}</a></span>

            </td>

            <td><input type="button" value="删除" ng-click="del(this)"/></td>

          </tr>

        </table>

      </p>

      <p ng-show="isc">

           I D:<input type="text" ng-model="a_id"/><br />

           商品名:<input type="text" ng-model="a_name"/><br />

           用户名:<input type="text" ng-model="a_user"/><br />

           手机号:<input type="text" ng-model="a_tel"/><br />

           价 值:<input type="text" ng-model="a_price"/><br />

          城 市:<input type="text" ng-model="a_city"/><br />

          <input type="button" value="保存" ng-click="add()"/>

      </p>

    </p>

  </body>

</html>

Copy after login

PS: There are still some functions in the code that are not perfect. Interested friends can test and modify them by themselves.

Related recommendations:

Example detailed explanation of AngularJS traversal to obtain array elements

Detailed explanation of Angular's implementation of form validation function

Some usages of angularJS

The above is the detailed content of Detailed example of Angular implementing more complex table filtering and deletion functions. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

How to install Angular on Ubuntu 24.04 How to install Angular on Ubuntu 24.04 Mar 23, 2024 pm 12:20 PM

Angular.js is a freely accessible JavaScript platform for creating dynamic applications. It allows you to express various aspects of your application quickly and clearly by extending the syntax of HTML as a template language. Angular.js provides a range of tools to help you write, update and test your code. Additionally, it provides many features such as routing and form management. This guide will discuss how to install Angular on Ubuntu24. First, you need to install Node.js. Node.js is a JavaScript running environment based on the ChromeV8 engine that allows you to run JavaScript code on the server side. To be in Ub

Use Java to write code to implement love animation Use Java to write code to implement love animation Dec 23, 2023 pm 12:09 PM

Realizing love animation effects through Java code In the field of programming, animation effects are very common and popular. Various animation effects can be achieved through Java code, one of which is the heart animation effect. This article will introduce how to use Java code to achieve this effect and give specific code examples. The key to realizing the heart animation effect is to draw the heart-shaped pattern and achieve the animation effect by changing the position and color of the heart shape. Here is the code for a simple example: importjavax.swing.

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

Master how Golang enables game development possibilities Master how Golang enables game development possibilities Mar 16, 2024 pm 12:57 PM

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

How to implement exact division operation in Golang How to implement exact division operation in Golang Feb 20, 2024 pm 10:51 PM

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

PHP Game Requirements Implementation Guide PHP Game Requirements Implementation Guide Mar 11, 2024 am 08:45 AM

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these

See all articles