选择记忆功能参考:https://market.sencha.com/extensions/ext-plugin-rememberselection

插件代码:

/*
* 记住列表选择状态
* 如果分组,支持点击全选按钮全选分组
* 需要添加以下css
.select .x-list-header:before {
content:"全选";
right:0;
position:absolute;
width:3em;
text-align:center;
}
*/ Ext.define('ux.plugin.Remember', {
extend: 'Ext.Component',
alias: 'plugin.remember',
xtype: 'remember',
config: {
//Reference a function in the plugin configuration to specify a default selection. It should return an Array or Mixed Collection of records whose corresponding list items will be selected by default.
getDefaultSelectionRecords: Ext.emptyFn, //Setting this property to true will supress the selection event when restoring default or "remembered" selections
supressEvent: false, //Private
list: null,
}, //Establishes the event handlers
init: function (list) {
var me = this;
me.setList(list);
var store = list.getStore();
if (list.getGrouped()) {
list.addCls('select');
//如果支持分组,监听表头点击事件
list.container.element.on({
delegate: 'div.x-list-header',
tap: 'onHeaderTap',
scope: me
});
list.setScrollToTopOnRefresh(false);
list.handlePinnedHeader = function () { };
}
//监听选中项,在选中之前执行
list.onBefore({
selectionchange: 'rememberSelections',
painted: 'restoreSelections',
scope: me
}); //监听数据源,在数据load之后执行,用以支持远程数据
store.onAfter(({
load: 'restoreSelections',
scope: me
}));
},
//点击表头
onHeaderTap: function (e, node) {
//根据节点css判断点击元素,也可以通过node.clientWidth - e.pageX计算点击位置来判断
var me = this, list = me.getList();
if (node.classList.length >= 4) {
var header = e.getTarget('div.x-list-header', 2, true),
scroller = e.getTarget('div.x-scroll-scroller', 3, true),
headers = scroller.query('div.x-list-header'),
index = header ? headers.indexOf(header.dom) : false,
store = list.getStore(),
groups = store.getGroups(),
group = groups[index],
records = group.children,
record,
i,
ln;
//进行全选操作
list.select(records, true);
}
},
//恢复选择状态
restoreSelections: function () {
var me = this,
list = me.getList(); //获取选中项
var selected = list.getStore().queryBy(function (record, id) {
return record.get('selected');
}).getRange(); if (!Ext.isEmpty(selected)) {
//开始选择
//重置选择状态,用以触发事件
list.deselectAll(true);
list.select(selected, false, me.getSupressEvent());
} else {
//如果没有“记住”选项,恢复所有默认选项
var fn = me.getGetDefaultSelectionRecords();
var defaultselectionrecords = fn(list);
if (!Ext.isEmpty(defaultselectionrecords)) {
list.select(defaultselectionrecords, false, me.getSupressEvent());
}
}
}, //记住选择状态
rememberSelections: function (list, records) {
var store = list.getStore();
var proxy = store.getProxy(); //如果是单选状态,重置选择标识状态
if (list.getMode() == 'SINGLE') {
store.each(function (record) {
if (record.get('selected')) {
record.set('selected', false);
}
});
} //记住选择状态
Ext.each(records, function (record) {
//可能会出错,抛出异常
try { record.set('selected', list.isSelected(record)); } catch (e) { }
}, this); ////重置筛选器
//if (!Ext.isEmpty(store.getFilters())) {
// store.filter();
//}
}
});

需要的关键css:

 .select .x-list-header {
padding:0.5em 1.02em;
}
.select .x-list-header .x-innerhtml {
color:#32BBC1;
}
.select .x-list-header:before {
content:"全选";
right:;
position:absolute;
width:3em;
text-align:center;
color:#8C8C8A;
}
.select .x-list-header,.select .x-list-item.x-list-item-tpl,.select .x-list-item.x-list-item-tpl.x-list-footer-wrap {
border-top:;
border-bottom:1px solid #F2F2E8;
background-image:none;
background-color:#E7E4DD;
background-image:linear-gradient(#E6E6DE,#DEDDD4);
}
.select .x-list-item.x-list-item-tpl.list-item-selected {
background-image:none;
background-color:#D9D5CC;
}
.select .x-list-item-tpl .x-list-disclosure {
border-radius:;
border:1px solid #D8D8D7;
background-image:none;
background-color:#E2E2E2;
background-image:linear-gradient(#E0E0E0,#EAEAEA);
}
.select .x-list-disclosure:before {
content:'3';
font-size:20px;
color:white;
}
.select .list-item-selected .x-list-disclosure {
border:1px solid #ADD157;
background-image:none;
background-color:#AEE03D;
background-image:linear-gradient(#AEE03E,#AEE03E);
}

用法:

/*
*选择对象
*/
Ext.define('app.view.tiny.People', {
alternateClassName: 'tinyPeople',
extend: 'Ext.List',
xtype: 'tinyPeople',
requires: ['ux.plugin.Remember'],
config: {
cls: 'list',
title: '对象选择',
cls: 'select',
mode: 'SIMPLE',
plugins: ['remember'],
selectedCls: 'list-item-selected',
itemTpl: '<div>{StudentName}</div>',
store: 'peopleList',
onItemDisclosure: true,
grouped: true
}
});

效果:

点击全选二字之后

sencha touch list 选择插件,可记忆已选项,可分组全选的更多相关文章

  1. sencha touch的开源插件和例子

    写了好久的sencha touch,没想到换工作竟然一年多没有搞了.因为项目的缘故收集了好多的组件,由于懒惰,没有整理,现在想想有点后悔了,再加上如果就这样丢弃,感觉有些遗憾,今天整理了一下放在git ...

  2. sencha touch list 批量选择扩展(2013-7-29)

    扩展js代码 /* *list多选扩展 */ Ext.define('ux.SimpleList', { alternateClassName: 'simpleList', extend: 'Ext. ...

  3. 使用 crosswalk-cordova 打包sencha touch 项目,再也不用担心安卓兼容问题!

    国内的安卓手机品牌众多,安卓操作系统碎片化也很严重,我们使用sencha touch 开发的应用不可避免的出现了各种无解的兼容性问题. 有时候我就在想,有没有既能支持cordova,又能让我们把Chr ...

  4. sencha touch 带本地搜索功能的selectfield(选择插件)

    带本地搜索功能的选择插件,效果图: 在使用selectfield的过程中,数据过大时,数据加载缓慢,没有模糊查询用户体验也不好, 在selectfield的基础上上稍作修改而成,使用方式同select ...

  5. SenCha Touch 与 EXTJS 安装Myeclipse 插件

    http://www.cnblogs.com/jirimutu01/default.html 关于SenchaEclipsePlugin插件的安装和使用 使用过eclipse开发java程序的人都知道 ...

  6. [Phonegap+Sencha Touch] 移动开发77 Cordova Hot Code Push插件实现自己主动更新App的Web内容

    原文地址:http://blog.csdn.net/lovelyelfpop/article/details/50848524 插件地址:https://github.com/nordnet/cord ...

  7. 选择移动web开发框架研究——有mui、frozenui以及Sencha Touch等

    纯粹的总结一下移动web开发框架,移动 web开发框架有jQuery Mobile .Sencha Touch等等,他们都来源于web开发,是成熟的框架,jQuery Mobile出自于jQuery家 ...

  8. sencha touch 2.2 为list PullRefresh插件添加refreshFn方法

    sencha touch 2.2 list PullRefresh插件没有refreshFn方法 但是我们又需要他,所以需要自行扩展 代码如下 /** * 重写下拉刷新插件,以支持refreshFn事 ...

  9. [Phonegap+Sencha Touch] 移动开发76 让cordova app訪问远端站点也能调用cordova插件功能

    原文链接:http://blog.csdn.net/lovelyelfpop/article/details/50735395 我相信.应该会有一些cordova开发人员想过实现以下这种app: 使用 ...

随机推荐

  1. Mybatis中#和$区别(带脑图)

    零.引言 使用 #{name} 的时候,MyBatis会进行预编译,防止SQL注入的问题(官方话) 用一个通俗一点的例子来解释,比如有如下MyBatis的SQL语句 21.#{}和${}的区别.png ...

  2. 如何获取模拟器安装的app的位置

    你可以死记下地址格式, 但是一旦不同的xcode和模拟器版本改变变了地址, 又得记, 从活动管理器里其实是可以直接查看的: Launch the app in the simulator Open A ...

  3. greenplum的用法

     gp建表的实例         gp 创建外部表的实例:(外部表不能建立分布键)              CREATE EXTERNAL TABLE user_app_tag (         ...

  4. vue如何正确销毁当前组件的scroll事件?

    将方法写出来,销毁在beforeDestroy写. mounted(){ window.addEventListener("scroll",this.handleFun), }, ...

  5. Mongodb数据结构及与MySql对比

    MySql一直是性价比最高的关系型数据库典范 MongoDB带来了关系数据库以外的NoSql体验. 让我们看一个简单的例子,我们将如何为MySQL(或任何关系数据库)和MongoDB中创建一个数据结构 ...

  6. php下webservice使用总结

    基于thinkphp3.2的 1.修改php配置 php.ini extension=php_soap.dll soap.wsdl_cache_enabled=0 2.soap有两种模式 wsdl和 ...

  7. python操作mysql数据库实现增删改查

    Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库,你可以选择适合你项目的数据库: ...

  8. 关于移位运算符>>和<<

    首先,移位运算符有三种,其操作类型只支持:byte / short / char / int和long五种. << 左移运算符,表示将左边的操作数的二进制数据向左移动*位,移动后空缺位以0 ...

  9. 利用opencv从USB摄像头获取图片

    由于opencv自带的VideoCapture函数直接从usb摄像头获取视频数据,所以用这个来作为实时的图像来源用于实体检测识别是很方便的. 1. 安装opencv 安装的步骤可以按照之前这个文章操作 ...

  10. Symbol.iterator的理解

    https://blog.csdn.net/margin_0px/article/details/82971545