Fixing more than one left column?

Fixing more than one left column?

WodinWodin Posts: 17Questions: 0Answers: 0
edited February 2012 in FixedHeader
FixedHeader seems to work pretty well for my needs as long as I use it with DataTables and not with:[code]document.getElementById("blah")[/code]
but I need to fix two left columns instead of just one.

How hard would it be to do this using FixedHeader?

Thanks.

Replies

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin
    It currently isn't possible to do that in FixedHeader. I'm sure it would be perfectly possible to implement in FixedHeader, its just a question of getting the time to do so!

    FixedColumns (for when the table is scrollable) however does support that: http://datatables.net/release-datatables/extras/FixedColumns/two_columns.html .

    Allan
  • WodinWodin Posts: 17Questions: 0Answers: 0
    Thanks for the quick reply. I'll give FixedColumns a try and see if it works for me, although I was hoping not to have to make the table scrollable.

    Perhaps if you point me in the right direction I'll be able to figure out how to make FixedHeaders able to fix more than one column?
  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin
    The _fnCloneTLeft function would be the starting point: https://github.com/DataTables/FixedHeader/blob/master/js/FixedHeader.js#L721

    Allan
  • WodinWodin Posts: 17Questions: 0Answers: 0
    Thanks, I'll have a look.
  • WodinWodin Posts: 17Questions: 0Answers: 0
    I tried FixedColumns, but had issues with the alignment (mainly of the top header with the rest of the table, especially when scrolling all the way to the right). Also things seemed not to work well when setting sScrollY to a value larger than the actual height of the table. Maybe I could work around the size issue. Not sure about the alignment issue. Anyway, it seems FixedHeader is closer to what I want.

    I had a brief look at the _fnCloneTLeft function yesterday. Did not understand all of it, but I'll have a better look later today to see if I can hard code it to the two left columns instead of one, which is what I need. If I can figure out how to do it more generically (i.e. allow the user to specify the number of columns) I'll do that instead.
  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin
    > I tried FixedColumns, but had issues with the alignment (mainly of the top header with the rest of the table, especially when scrolling all the way to the right)

    I assume you are using 1.9.0 - there is a bug in that sadly. It is addressed in 1.9.1.dev ( http://datatables.net/download ).

    Allan
  • WodinWodin Posts: 17Questions: 0Answers: 0
    Ah yes, I am using 1.9.0. Thanks, I'll have a look at 1.9.1.dev tomorrow.

    This seems to do what I want wrt. fixing the 2 left columns (quick'n'dirty), but I suspect I need to do something about the widths too:

    [code]@@ -740,12 +738,12 @@ FixedHeader.prototype = {
    nTable.appendChild( jQuery("tfoot", s.nTable).clone(true
    }

    - jQuery('thead tr th:gt(0)', nTable).remove();
    - jQuery('tfoot tr th:gt(0)', nTable).remove();
    + jQuery('thead tr th:gt(1)', nTable).remove();
    + jQuery('tfoot tr th:gt(1)', nTable).remove();

    /* Remove unneeded cells */
    $('tbody tr', nTable).each( function (k) {
    - $('td, th', this).filter(':gt(0)').remove();
    + $('td, th', this).filter(':gt(1)').remove();
    } );

    this.fnEqualiseHeights( 'tbody', nBody.parentNode, nTable );
    [/code]
  • CreazyDevCreazyDev Posts: 1Questions: 0Answers: 0
    edited March 2012
    Here is the hack for "Fixing more than one left/right column"

    after lil playing with the code figure out the hack for this

    in _fnCloneTLeft function

    change the;
    [code]
    /* Remove unneeded cells */
    $('tbody tr', nTable).each( function (k) {
    $('td:gt(0)', this).remove();
    } );
    [/code] 
    To ex.;
    [code] 
    $('td:gt(2)', this).remove();
    [/code]

    Its going to keep first 3 columns in the left, so after each scrolling when the oCache gets updated and first 3 columns gonna stay in place.

    same idea can be applied to fixing right columns too ;]

    [first I tried updating the cells text after fixedLeft column div gets created but then noticed oCache gets refreshed on every ui scroll, that didn't work]

    Thanks Allen for defining the starting point...


    [code] 
    I am in love with DataTables
    [/code]
  • _g__g_ Posts: 11Questions: 0Answers: 0
    Thanks allan, Wodin, CreazyDev! I have posted a patch which puts it all together here: http://www.datatables.net/forums/discussion/10459/patch-change-fixedheader-leftright-properties-to-int
This discussion has been closed.