flexigrid 获取选中的行

来源:互联网 发布:面试淘宝客服无经验的 编辑:程序博客网 时间:2024/05/21 00:45

首先设置flexigrid为单选模式:

$("#subUsers").flexigrid({dataType: 'json',width: 237,height: 267,singleSelect: true,colModel : [{hide: '_id', name: 'id', width: 158, sortable: true, align: 'left'},{display: email, name: 'email', width: 158, sortable: true, align: 'left'},{display: description, name: 'description', width: 77, sortable: true, align: 'left'},]});

注意上面的singleSelect: true 设置。

现在有三列,我希望获取选中的那行的第一列。代码如下:

$('#subUsers').each(function () {id = $('.trSelected').children('td').eq(0).children('div').html();});

subUsers 是 flexigrid对应的table元素的id, 因此$('#subUsers') 代表了table对应的jquery对象,之后each函数遍历这个jquery对象,里面只有一个就是tbody.

flexigrid会为所有被选中的行添加.trSelected 风格,因此通过$('.trSelected')就可以获得tr那行,再通过children方法去一层层找子元素,最后找到div里面的值,就是第一列显示的数据。

原创粉丝点击