Flexigrid get selected row column values

I am new to flexigrid. can someone please let me know how to get the selected row for each column value.?

How to get each column name (reportName and reportDescription)? because I push // all the data into an array as below.

I use the code below to get the selected rows. But it returns null. could you help me?

//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() ); }); }); 

Thank you Pon Kumar Pandian

+4
source share
5 answers

I'm not sure that you already understood this, but I am going to leave this answer here if someone else in the same situation stumbles on your question, like me.

Setting "sortable: false" in the column removes the attribute "abbr" from the "td" that is generated by Flexigrid. This means that you cannot use the recommended solution to get the selected row.

I myself modified the flexigrid.js file to fix this problem.

Flexigrid previously added the attribute "abbr" if the column had a name and had "sortable: true". I removed the condition "sortable: true".

This, in turn, also meant that columns would always be sortable. To prevent this, I added the "sortable" attribute, which will only be set if the column is "sortable: true"

After that, I had to go through and find all the situations in which "abbr" was used as a condition for sorting and replaced it with a check for "sortable".

What is it.

I uploaded the file to mediafire if you just want it to be able to download and use. There are a few too many changes in non-specific places for me to show my code changes here. If necessary, I can provide a distinction or more explanations. Note that "sortable: true" still works with my fix.

+6
source

I had the same problem and decided to use it using the following code

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

Just add it to the function and replace the name id #schoolist and abbr with the name of the desired column.

+2
source

try:

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

or

Using flexgrid with CI, add below code to your custom button event

 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 Code:

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

Check screen:

enter image description here

0
source

Adding the following function to the source flexigrid.js returns an array of selected rows.

 $.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; }; 

Application:

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

Find value by column name

 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; } 
0
source

All Articles