分类搜索实现

1.添加搜索框

打开Index视图,添加一个搜索框,代码如下:
...
<div class="portlet light">
<div class="portlet-title portlet-title-filter">
<div class="inputs inputs-full-width">
<div class="portlet-input">
<form>
<div class="input-group">
<input id="CategoriesTableFilter" class="form-control" placeholder="@L("SearchWithThreeDot")" type="text" value="@ViewBag.FilterText">
<span class="input-group-btn">
<button id="GetCategoriesButton" class="btn default" type="submit"><i class="icon-magnifier"></i></button>
</span>
</div>
</form>
</div>
</div>
</div>
<div class="portlet-body">
...
保存,刷新页面,效果如下:

2.搜索点击事件

打开Index.js【..\MyCompanyName.AbpZeroTemplate.Web\Areas\Mpa\Views\Category\Index.js】
添加如下代码:
//新建分类点击事件
$('#CreateNewCategoryButton').click(function () {
_createModal.open();
});
//搜索点击事件
$('#GetCategoriesButton').click(function (e) {
//取消事件的默认动作
e.preventDefault();
getCategories();
});
然后修改getCategories函数为如下:
function getCategories(reload) {
if (reload) {
_$categoriesTable.jtable('reload');
} else {
_$categoriesTable.jtable('load', {
filter: $('#CategoriesTableFilter').val()
});
}
}

3.创建Dto

在CategoryApp\Dto下创建一个类GetCategoriesInput.cs
【..\MyCompanyName.AbpZeroTemplate.Application\CategoryApp\Dto\GetCategoriesInput.cs】
代码如下:
public class GetCategoriesInput : PagedAndSortedInputDto, IShouldNormalize
{
public string Filter { get; set; }
public void Normalize()
{
if (string.IsNullOrEmpty(Sorting))
{
Sorting = "Name";
}
}
}

4.修改方法

打开文件ICategoryAppService
【..\MyCompanyName.AbpZeroTemplate.Application\CategoryApp\ICategoryAppService.cs】
GetCategories方法修改为如下:
PagedResultOutput<CategoryOutput> GetCategories(GetCategoriesInput input);
对应的实现类CategoryAppService,修改GetCategories方法如下:
public PagedResultOutput<CategoryOutput> GetCategories(GetCategoriesInput input)
{
//创建映射
Mapper.CreateMap<Category, CategoryOutput>();
var result=_categoryRepository.GetAll();
if (!string.IsNullOrWhiteSpace(input.Filter))
{
result=result.Where(a => a.Name.Contains(input.Filter));
}
int totalCount = result.Count();
return new PagedResultOutput<CategoryOutput>(
totalCount,
Mapper.Map<List<CategoryOutput>>(result.ToList())
);
}

5.测试

生成项目,刷新页面,搜索框输入字符进行查询
 

表格分页实现

由于上面已经实现了一些代码,分页实现起来相对简单,只要修改CategoryAppService类中的GetCategories方法即可,代码如下:
public PagedResultOutput<CategoryOutput> GetCategories(GetCategoriesInput input)
{
//创建映射
Mapper.CreateMap<Category, CategoryOutput>();
var result=_categoryRepository.GetAll();
if (!string.IsNullOrWhiteSpace(input.Filter))
{
result=result.Where(a => a.Name.Contains(input.Filter));
}
int totalCount = result.Count();
var list=result.OrderBy(input.Sorting).PageBy(input).ToList();//分页
return new PagedResultOutput<CategoryOutput>(
totalCount,
Mapper.Map<List<CategoryOutput>>(list)
); }
同时引用using System.Linq.Dynamic;
以支持OrderBy传入string作为参数,这是一个扩展方法
这里顺便把排序也完成了。
点击列可实现排序
至此,整个分类功能已经完成,可以正常使用,如果要求更高,可以对按钮进行权限控制,不同角色操作不同按钮,请继续下一篇:权限控制

ASP.NET Zero--14.一个例子(7)商品分类管理-分类搜索及分页的更多相关文章

  1. [asp.net core]SignalR一个例子

    摘要 在一个后台管理的页面想实时监控一些操作的数据,想到用signalR. 一个例子 asp.net core+signalR 使用Nuget安装包:Microsoft.AspNetCore.Sign ...

  2. ASP.NET Zero--13.一个例子(6)商品分类管理-删除分类

    1.添加按钮 首先添加一个删除按钮,打开文件Index.js[..\MyCompanyName.AbpZeroTemplate.Web\Areas\Mpa\Views\Category\Index.j ...

  3. ASP.NET Zero--8.一个例子(1)菜单添加

    以一个商品分类管理功能来编写,代码尽量简单易懂.从一个实体开始,一直到权限控制,由浅到深一步步对功能进行完善. 1.打开语言文件 [..\MyCompanyName.AbpZeroTemplate.C ...

  4. 这算是ASP.NET MVC的一个大BUG吗?

    这是昨天一个同事遇到的问题,我觉得这是一个蛮大的问题,而且不像是ASP.NET MVC的设计者有意为之,换言之,这可能是ASP.NET MVC的一个Bug(不过也有可能是保持原始请求数据而作的妥协). ...

  5. 从一个例子中体会React的基本面

    [起初的准备工作] npm init npm install --save react react-dom npm install --save-dev html-webpack-plugin web ...

  6. Http,Https (SSL)的Url绝对路径,相对路径解决方案Security Switch 4.2 中文帮助文档 分类: ASP.NET 2014-10-28 14:09 177人阅读 评论(1) 收藏

    下载地址1:https://securityswitch.googlecode.com/files/SecuritySwitch%20v4.2.0.0%20-%20Binary.zip 下载地址2:h ...

  7. [ASP.NET MVC2 系列] ASP.Net MVC教程之《在15分钟内用ASP.Net MVC创建一个电影数据库应用程序》

    [ASP.NET MVC2 系列]      [ASP.NET MVC2 系列] ASP.Net MVC教程之<在15分钟内用ASP.Net MVC创建一个电影数据库应用程序>       ...

  8. 《The art of software testing》的一个例子

    这几天一直在看一本书,<The art of software testing>,里面有一个例子挺有感触地,写出来和大家分享一下: [问题] 从输入对话框中读取三个整数值,这三个整数值代表 ...

  9. 一个例子读懂 JS 异步编程: Callback / Promise / Generator / Async

    JS异步编程实践理解 回顾JS异步编程方法的发展,主要有以下几种方式: Callback Promise Generator Async 需求 显示购物车商品列表的页面,用户可以勾选想要删除商品(单选 ...

随机推荐

  1. 一个action读取另一个action里的session

    action 1: private Map session; session.put("projectname_session", request1.getParameter(&q ...

  2. java中基本数据类型和C语言中基本数据类型转换

    java中 1 short = 2 byte 1 char  = 2 byte 1 int    = 4 byte 1 long = 8 byte C语言中 typedef unsigned char ...

  3. smali插入log,打印变量

    一:Log打印变量: Log打印字符串: #liyanzhong debug const-string v1, "TAG" const-string v2, "xunbu ...

  4. CodeForces 610C Harmony Analysis

    构造 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> us ...

  5. ARM架构解析

    ARM架构解析 (2014-11-23 21:56:53) 转载▼ 标签: francis_hao arm架构 arm核 soc 分类: MCU 先来谈一下ARM的发展史:1978年12月5日,物理学 ...

  6. With PHP frameworks, why is the “route” concept used?

    http://programmers.stackexchange.com/questions/122190/with-php-frameworks-why-is-the-route-concept-u ...

  7. Redis 代理 twemproxy

    4台 redis 服务器 172.16.1.37:6379   - 1 172.16.1.36:6379   - 2 172.16.1.35:6379   - 3 172.16.1.34:6379   ...

  8. /bin/sh 与 /bin/bash 的区别

    /bin/sh 与 /bin/bash 的区别,用 : 截取字符串不是POSIX 标准的. 区别 sh 一般设成 bash 的软链 (symlink) ls -l /bin/sh lrwxrwxrwx ...

  9. cocopods安装与使用

    转自http://www.cnblogs.com/jys509/p/4839803.html Cocoapods安装步骤 1.升级Ruby环境 sudo gem update --system 如果R ...

  10. MYSQL一次性能优化实战经历[转]

    每次经历数据库性能调优,都是对性能优化的再次认识.对自己知识不足的有力验证,只有不断总结.学习才能少走弯路. 一.性能问题描述 应用端反应系统查询缓慢,长时间出不来结果.SQLServer数据库服务器 ...