andycrespo27 / flexigrid

Automatically exported from code.google.com/p/flexigrid
0 stars 0 forks source link

No method to get data for a cell #4

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
There is no method to get data for a specific cell. I am building a sample 
application where i need to get the data for some columns(using column name 
specified in colModel) of the last row in the grid.

Original issue reported on code.google.com by mr.mu...@gmail.com on 11 Sep 2008 at 1:02

GoogleCodeExporter commented 8 years ago
This could be done using native javascript (or jQuery).

Original comment by eric.caron on 22 Dec 2010 at 3:41

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
hello, I have solution..

for grid with colModel like this:
colModel : [
  {name: 'name',   display: 'NAME'   },
  {name: 'status', display: 'STATUS' },
  {name: 'sign',   display: 'SIGN'   }
]
we can obtain cell data by using hDiv, like this:

$('#grid02').click(function(event){
    var grid = this;
    var flex = $(grid).closest('.flexigrid');
    var abbr = [];
    $('.hDiv th', flex).each( function(index){
        abbr[index] = $(this).attr('abbr');
    });

    $('.res').html('');//div.res - area for display result
    $('.trSelected', grid).each( function(){
        $('.res').html(
            $('.res').html() +
            '<br />rowId: '  + $(this).attr('id').substr(3) +
            '<br />name: '   + $('td:nth-child('+ (1+$.inArray('name',abbr)) +')>div', this).html() +
            '<br />sign: '   + $('td:nth-child('+ (1+$.inArray('sign',abbr)) +')>div', this).html() +
            '<br />status: ' + $('td:nth-child('+ (1+$.inArray('status',abbr)) +')>div', this).html() 
        );
    });
});

But. If we add 2 lines to flexigrid code, we get data by attribute like this:

$('#grid02').click(function(event){
    $('.res').html('');//div.res - area for display result
    $('.trSelected', this).each( function(){
        $('.res').html(
            $('.res').html() +
            '<br />rowId: '  + $(this).attr('id').substr(3) +
            '<br />name: '   + $('td[abbr="name"] >div', this).html() +
            '<br />sign: '   + $('td[abbr="sign"] >div', this).html() +
            '<br />status: ' + $('td[abbr="status"] >div', this).html() 
        );
    });
});

patch: in flexigrid addData
codeblock  if (p.dataType=='json')

$('thead tr:first th',g.hDiv).each
(
    function ()
    {
        var td = document.createElement('td');
        var idx = $(this).attr('axis').substr(3);
        td.align = this.align;
        td.innerHTML = row.cell[idx];
/*!*/   $(td).attr('abbr', $(this).attr('abbr'));
        $(tr).append(td);
        td = null;
    }
);

codeblock  if (p.dataType=='xml')

$('thead tr:first th',g.hDiv).each
(
    function ()
    {
        var td = document.createElement('td');
        var idx = $(this).attr('axis').substr(3);
        td.align = this.align;
        td.innerHTML = $("cell:eq("+ idx +")",robj).text();
/*!*/   $(td).attr('abbr', $(this).attr('abbr'));
        $(tr).append(td);
        td = null;
    }
);

Original comment by ymkin....@gmail.com on 7 Mar 2011 at 10:48