Skip to content

Commit

Permalink
Merge branch 'master' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
miemiedev committed Jun 3, 2013
2 parents 7aa7d96 + 488d685 commit e65dbce
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions examples/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,10 @@ <h2>四.事件</h2>
<td>数据加载失败后执行。</td>
</tr>
<tr>
<td>rowSelected</td>
<td>cellSelected</td>
<td><em>function(e, item, rowIndex, colIndex){}</em></td>
<td>
表格中的行被选择后执行。item:被选择行对应的数据对象;rowIndex:行索引;colIndex:列索引。
表格中的单元格被选择后执行。item:被选择单元格所在行对应的数据对象;rowIndex:行索引;colIndex:列索引。
</td>
</tr>
<tr>
Expand Down
15 changes: 9 additions & 6 deletions examples/examples1.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
]},
{ title:'最高价', name:'HIGHESTPRICE' ,width:60, align:'right', hidden: true, sortable: true, type: 'number', renderer: fixed2},
{ title:'最低价', name:'LOWESTPRICE' ,width:60, align:'right', hidden: true, sortable: true, type: 'number', renderer: fixed2},
{ title:'操作', name:'' ,width:100, align:'center', lockWidth:true, lockDisplay: true, renderer: function(val){
return '<button class="btn btn-primary">查看</button>'
{ title:'操作', name:'' ,width:150, align:'center', lockWidth:true, lockDisplay: true, renderer: function(val){
return '<button class="btn btn-info">查看</button> <button class="btn btn-danger">删除</button>'
}}
];

Expand All @@ -147,17 +147,20 @@
});


mmg.on('rowSelected', function(e, item, rowIndex, colIndex){
console.log('rowSelected!');
mmg.on('cellSelected', function(e, item, rowIndex, colIndex){
console.log('cellSelected!');
console.log(this);
console.log(e);
console.log(item);
console.log(rowIndex);
console.log(colIndex);
//查看
if(colIndex === 1 || colIndex === 14){
if($(e.target).is('.btn-info, .btnPrice')){
e.stopPropagation(); //阻止事件冒泡
alert(JSON.stringify(item));
return false;//返回false取消执行选中或取消选中的操作
}else if($(e.target).is('.btn-danger') && confirm('你确定要删除该行记录吗?')){
e.stopPropagation(); //阻止事件冒泡
mmg.removeRow(rowIndex);
}
}).on('loadSuccess', function(e, data){
//这个事件需要在数据加载之前注册才能触发
Expand Down
2 changes: 1 addition & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ <h3 >例 2:默认列宽</h3>
<h2>七、选择行</h2>
<p>
表选项<em>multiSelect</em>设置表格是否可多选,默认为单选。可通过表操作<em>$('#table').mmGrid('selected')</em>获取选择的行对象。
当光标单击单元格时触发<em>onSelected</em>事件,该事件可在表选项设置。当该事件返回<em>false</em>取消执行选中或取消选中的操作
当光标单击单元格时触发<em>cellSelected</em>事件,该事件可在表选项设置。
</p>
<div class="grid-50">
<h3 >例 1:行多选</h3>
Expand Down
14 changes: 8 additions & 6 deletions src/mmGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -536,17 +536,19 @@

//选中事件
var $body = this.$body;
$body.on('click','td',function(){
$body.on('click','td',function(e){
var $this = $(this);
var event = jQuery.Event("cellSelected");
event.target = e.target;
that.$body.triggerHandler(event, [$.data($this.parent()[0], 'item'), $this.parent().index(), $this.index()]);


var isSelect = that.$body.triggerHandler('rowSelected', [$.data($this.parent()[0], 'item'), $this.parent().index(), $this.index()]);

if(isSelect === false){
if(event.isPropagationStopped()){
return;
}
if(!$this.parent().hasClass('selected')){
that.select($this.parent().index());
}else{
that.deselect($this.parent().index());
}
});

Expand Down Expand Up @@ -1261,7 +1263,7 @@
, showBackboard: true
, plugins: [] //插件 插件必须实现 init($mmGrid)和params()方法,参考mmPaginator
};
// event : loadSuccess(e,data), loadError(e, data), rowSelected(item, rowIndex, colIndex)
// event : loadSuccess(e,data), loadError(e, data), cellSelected(e, item, rowIndex, colIndex)
// rowInserted(e,item, rowIndex), rowUpdated(e, oldItem, newItem, rowIndex), rowRemoved(e,item, rowIndex)
//

Expand Down

0 comments on commit e65dbce

Please sign in to comment.