4

我是 flexigrid 的新手。任何人都可以让我知道如何获取所选行的每列值。?

如何获取每个列名(reportName 和 reportDescription)?因为我将//所有数据推入数组,如下所述。

我正在使用下面的代码来获取选定的行。但它返回null。你能帮助我吗?

//Column. <br/>


colModel: [
  { display: 'WidgetID', name: 'WidgetID', width: 50, sortable: true, align: 'left', hide: true },
  { display: 'Widget Name', name: 'WidgetName', width: 170, sortable: true, align: 'left' },
  { display: 'IsClientReport', name: 'IsClientReport', width: 50, sortable: false, align: 'left', hide: true },
  { display: 'ClientReportID', name: 'ClientReportID', width: 50, sortable: false, align: 'left', hide: true },
  { display: 'ReportType', name: 'ReportType', width: 280, sortable: true, align: 'left' }
],

$('#grid01').click(function(event){ 
  $('.trSelected', this).each( function(){ 
      console.log( ' rowId: ' + $(this).attr('id').substr(3) + ' IsClientReport: ' + $('td[abbr="IsClientReport"] >div', this).html() + ' sign: ' + $('td[abbr="WidgetID"] >div', this).html() + ' ReportType: ' + $('td[abbr="ReportType"] >div', this).html() ); 
  }); 
});

谢谢,庞库马尔潘迪安

4

5 回答 5

6

不确定您是否已经弄清楚了,但是我将把这个答案留在这里,以防其他处于相同情况的人像我一样偶然发现您的问题。

在列上设置 'sortable: false' 会从 Flexigrid 生成的 'td' 中删除 'abbr' 属性。这意味着您不能使用推荐的解决方案来获取选定的行。

我自己修改了 flexigrid.js 文件来解决这个问题。

Flexigrid 以前仅在列具有“名称”并且具有“可排序:真”时才添加“缩写”属性。我删除了“可排序:真”的条件。

反过来,这也意味着列将始终是可排序的。为了防止这种情况,我添加了一个“可排序”属性,该属性仅在列是“可排序:真”时设置

之后,我必须检查所有使用“abbr”作为排序条件的情况,并将其替换为“可排序”检查。

而已。

如果您只想下载和使用这个文件,我会将文件上传到 mediafire 。非特定位置的更改太多,我无法在此处显示我对代码的更改。如果需要,我可以提供差异或更多解释。请注意,'sortable: true' 仍然适用于我的修复。

于 2012-10-31T03:09:28.137 回答
2

我有同样的问题,并通过使用以下代码解决了它

 jQuery('#schoolist .trSelected').each( function(){
                alert(jQuery('[abbr="name"]',this).text());

            });

只需将其添加到函数中,并将 id #schoolist 和 abbr 名称替换为您需要的列的名称。

于 2013-07-20T13:50:35.710 回答
0

请参阅此处的 FlexiGrid 常见问题解答: http ://code.google.com/p/flexigrid/wiki/FAQ#Get_selected_row

于 2012-08-13T23:29:24.493 回答
0

你可以试试:

$('#grid01').click(function(event){
    $('.trSelected', this).each( function(){
        console.log(
            '  rowId: '  + $(this).attr('id').substr(3) +
            '  name: '   + $('td[abbr="name"] >div', this).html() +
            '  sign: '   + $('td[abbr="sign"] >div', this).html() +
            '  status: ' + $('td[abbr="status"] >div', this).html() 
        );
    });
});

或者

将 flexgrid 与 CI 一起使用,然后在您的自定义按钮事件中添加以下代码

function test(com, grid) {  
    if (com == 'Export') {
        var data = ($('.bDiv', grid).html());
        $('.bDiv tbody tr', grid).each(function () {
            console.log('  rowId: ' + $(this).attr('id').substr(3) + '  name: ' + $('td[abbr="name"] >div', this).html() + '  coupon_no: ' + $('td[abbr="coupon_no"] >div', this).html() + '  status: ' + $('td[abbr="status"] >div', this).html());
        });
    }   
}

PHP CI 代码:

$buttons[] = array('Export','excel','test');

检查屏幕:

在此处输入图像描述

于 2013-03-15T00:42:53.413 回答
0

将以下函数添加到 flexigrid.js 源将返回一个选定行的数组。

$.fn.selectedRows = function (p) {
    var arReturn = [];
    var arRow = [];
    var selector = $(this.selector + ' .trSelected');
    $(selector).each(function (i, row) {
        arRow = [];
        $.each(row.cells, function (c, cell) {
            var col = cell.abbr;
            var val = cell.innerText;
            var idx = cell.cellIndex;

            arRow.push(
                {
                    Column: col,
                    Value: val,
                    CellIndex: idx
                }
                );
        });
        arReturn.push(arRow);

    });
    return arReturn;
};

用法:

var rows = $('#datagrid').selectedRows();

按列名查找值

function getColValueByName(cols, colName) {
   var retVal = '';
   var param = $.grep(cols, function (e) {
    var found = e.Column == colName;
    if (found != null && found != undefined & found) {
        retVal = e.Value;
    }
});
   return retVal;
}
于 2013-04-29T15:50:57.647 回答