DaltonPimmel / flexigrid

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

Attribute 'abbr' assigned to cells only if the column is sortable. #46

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

How to get data from a table? For example, data of the selected row.
This question has already been asked: 
http://code.google.com/p/flexigrid/issues/detail?id=4&can=1

The difficulty lies in linking: column_name - data. That is why the order of 
columns can be changed, and we can not use index in the array of row cells.

I suggested to use the attribute 'abbr' for table cells. And this patch is 
included in version 1.1.

But. Attribute 'abbr' assigned to cells only if the column is sortable.
I found a place in the code where it is defined. Lines ~690:

if (p.colModel) { //create model if any
    thead = document.createElement('thead');
    var tr = document.createElement('tr');
    for (var i = 0; i < p.colModel.length; i++) {
        var cm = p.colModel[i];
        var th = document.createElement('th');
        th.innerHTML = cm.display;
/*!*/       if (cm.name && cm.sortable) {
            $(th).attr('abbr', cm.name);
        }
        $(th).attr('axis', 'col' + i);
        if (cm.align) {
            th.align = cm.align;
        }
        if (cm.width) {
            $(th).attr('width', cm.width);
        }
        if ($(cm).attr('hide')) {
            th.hidden = true;
        }
        if (cm.process) {
            th.process = cm.process;
        }
        $(tr).append(th);
    }
    $(thead).append(tr);
    $(t).prepend(thead);
} // end if p.colmodel

But the simple removal of the condition leads to the column becomes sortable, 
regardless of the definition in colmodel.

Thus, working with the attribute 'abbr' is only possible in sortable columns. 
Or we need to revise the code.

Original issue reported on code.google.com by ymkin....@gmail.com on 16 Jun 2011 at 8:07

GoogleCodeExporter commented 8 years ago
My solution adds a HTML5 attribute called 'data-name' to every cell. This could 
be turned on by setting the dataAttr to true. The default is off to provide 
valid backwards compatiblity to HTML and XHTML.

This is a clean way to get data from every cell by reading the value from the 
'data-name' attribute.

I've attached a patch for this and created it in the js directory, so it has to 
be applied there.

Chris

Original comment by writech...@gmx.net on 15 Sep 2011 at 8:48

Attachments:

GoogleCodeExporter commented 8 years ago
I've forgotten to mention that this patch is based on Revision 13 from your 
read-only repo.

Original comment by writech...@gmx.net on 15 Sep 2011 at 8:50