adding empty row before matched cell data

adding empty row before matched cell data

indymxindymx Posts: 63Questions: 3Answers: 0
edited March 2014 in DataTables 1.10
Consider the following table data: (date and time make up a column)

[quote]

03-13 16:30 03-15 17:00 03-15 03:00
03-14 21:00 03-17 08:00 03-15 04:00
03-14 16:00 03-16 08:00 03-15 05:30
03-12 18:00 03-15 10:00 03-15 06:30
03-13 18:00 03-15 00:00 03-15 06:30
03-13 15:00 03-17 08:00 03-15 06:30

[/quote]

Is there anyway I could insert an empty row with a class attached to color the background before the first row that matches "06:30" in column 3?

I only need one instance of the empty row..

Replies

  • indymxindymx Posts: 63Questions: 3Answers: 0
    Not possible then?
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    An empty row as in one which doesn't belong to the DataTable, but is in the table? If so, then yes, quote possible. The basic technique I would suggest for this, is shown in this example: http://datatables.net/release-datatables/examples/advanced_init/row_grouping.html .

    Allan
  • indymxindymx Posts: 63Questions: 3Answers: 0
    I get row grouping, I'm doing that now.


    And as for the logic involved to determine which row I want to place the empty above, I've got that worked out in my mind. I just need to insert an empty row above that one target row.

    On our current setup for this "app" (a Google Docs Spreadsheet ICK!!) I insert a blank row above the next row that will be a concern for the next shift.

    I work 6 pm to 6 am, so anything with an scheduled update time of 0600 or later I don't care about, so a row with a red background is inserted above that so that I can sort of see visually what I need to worry about and what doesn't concern me.

    I'd like to do the same on this, however, the rows won't be in the DB, but generated on the fly. So yes, it won't belong to the DataTable.

    What I worked out lastnight while trying to go to sleep is to test the next update time against a variable set to "06:00" and if it's greater or equal that is my target. Then to make sure I'm not targeting more rows than one, change my target variable to "99:99" so it will never match again.

    That should isolate the one target row I'm looking for.

    Now I just need to know how to insert an empty row with a particular CSS class attached above the target row in the display.
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    > Now I just need to know how to insert an empty row with a particular CSS class attached above the target row in the display.

    You'd do it in exactly the same way as the row grouping does, would you not? Loop over the rows, find the one you want and insert a new, empty row, with your class, before it.

    Allan
  • indymxindymx Posts: 63Questions: 3Answers: 0
    [code]
    "drawCallback": function ( settings ) {
    var api = this.api();
    var rows = api.rows( {page:'current'} ).nodes();
    var last=null;
    api.column(1, {page:'current'} ).data().each( function ( group, i ) {
    if ( last !== group ) {
    $(rows).eq( i ).before(
    ''+group+''
    );
    last = group;
    }
    });
    }
    [/code]

    This is how I'm grouping.. I'm not sure how to implement the check here to create the one row I need
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    It looks like you already have all the basic concepts of what you need.

    [code]
    var data = api.column(1, {page:'current'} ).data();
    [/code]

    For example gives you the data for the cells in column 1. If that is the column you want to check for your logic to insert the extra row, use that, loop over the returned array and when you find the insert point, use the `row` array item at the same index and a simple jQuery `insertBefore()` .

    Allan
  • indymxindymx Posts: 63Questions: 3Answers: 0
    Awesome . I'll play with that and see where it takes me.
  • indymxindymx Posts: 63Questions: 3Answers: 0
    it's evaluating the variable against the column, but I fear I'm just too dense today to see my error.

    I'm getting the "cutoff" on every grouped row. Not exactly what I planned on.

    [code]
    var cutoffN = dateFormat(new Date(), "mm-dd 06:00");

    "drawCallback": function ( settings ) {
    var api = this.api();
    var rows = api.rows( {page:'current'} ).nodes();
    var last=null;
    api.column(1, {page:'current'} ).data().each( function ( group, i ) {
    if ( last !== group ) {
    $(rows).eq( i ).before(
    ''+group+''
    );
    last = group;
    }
    });
    api.column(8, {page:'current'} ).data().each( function ( group, i ) {
    if ( last >= cutoffN ) {
    $(rows).eq( i ).before(
    'Cutoff'
    );
    cutoffN = dateFormat(new Date(), "mm-dd 99:99");

    }
    });
    }
    });
    [/code]
  • indymxindymx Posts: 63Questions: 3Answers: 0
    I've tried everything I can think of with this.. It's just not working and I can't figure out why..
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    I'm not entirely sure what the `last` variable as to do with your `cutoffN` one, unless you want it to be specifically related to the logic for the row grouping? However, does that expression ever evaluate to `true` ? Use a `console.log` to check it out.

    Allan
  • indymxindymx Posts: 63Questions: 3Answers: 0
    no.. I've tried the last variable and api.column(8).. no dice.. the api.column both spit errors about trying to compare an object or something like that..
  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin
    I don't really understand what the above code is trying to do to be honest. Is it actually meant to be combining the logic of the row grouping and the extra insert row?
  • indymxindymx Posts: 63Questions: 3Answers: 0
    Honestly don't know why I was trying to do it with the row grouping..

    I added my test to the same bit of code I'm using to color my rows. seems more logical place. It's matching the cells I'm looking for, however, not inserting the row before the matched row.

    [code]
    if (data.nextUpdate >= cutoffN) {
    //alert(cutoffN);
    $( 'Cutoff' ).insertBefore( '.group' );
    cutoffN = dateFormat(new Date(), "mm/dd 99:99");
    }
    [/code]

    based on what I read in the jquery docs, this should work.
  • indymxindymx Posts: 63Questions: 3Answers: 0
    except it's matching every row after the target I'm looking for, not just that one target..
  • indymxindymx Posts: 63Questions: 3Answers: 0
    Throwing in the towel on this one.. Just not worth the hassle
This discussion has been closed.