2012-08-08 26 views
4

我是flexigrid的新手。任何人都可以讓我知道如何獲得每列值的選定行。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()); 
    }); 
}); 

感謝, PON庫馬爾Pandian

回答

0
+0

我使用下面的代碼來獲取選定的行。但它返回null。你能幫我一樣嗎? $('#grid01')。click(function(event){('。trSelected',this).each(function(){ console.log( 'rowId:'+ $(this).attr '')。substr(3)+ 'name:'+ $('td [abbr =「name」]> div',this).html()+ 'sign:'+ $('td [abbr =「sign」]> div',this).html()+ 'status:'+ $('td [abbr =「status」]> div',this).html() ); }); }); – 2012-08-17 06:51:19

+0

我有同樣的問題,有人找出它嗎? – 2013-03-13 00:20:09

6

不知道如果你已經理解了它,但我要離開這裏了這個答案如果其他人在同樣的情況下像我一樣絆倒你的問題。

在列上設置'sortable:false'將刪除由Flexigrid生成的'td'中的'abbr'屬性。這意味着您不能使用推薦的解決方案獲取選定的行。

我自己修改了flexigrid.js文件來解決這個問題。

如果一列有'name'並且'sortable:true',Flexigrid以前只添加'abbr'屬性。我刪除了'sortable:true'的條件。

這反過來也意味着列總是是可排序的。 爲了防止這種情況,我添加了一個「排序」的屬性,這將只設置如果列是「排序:真正的」

在那之後,我不得不經歷並找到「簡稱」正在使用的所有情況作爲分揀的條件,並將其替換爲「可分揀」的支票。

就是這樣。

I uploaded the file to mediafire如果你只是想能夠下載和使用這一個,而不是。對於我來說,在非特定的地方有一些太多的變化來顯示我的代碼更改。如果需要,我可以提供差異或更多的解釋。請注意,'sortable:true'仍然適用於我的修復程序。

0

你CA嘗試:

$('#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'); 

檢查S creen:

enter image description here

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; 
} 
2

我有同樣的問題,並通過使用下面的代碼

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

      }); 
解決它

只需將它添加到函數中,並用您需要的列名替換id #schoolist和abbr名稱即可。