adding empty row before matched cell data
adding empty row before matched cell data
indymx
Posts: 63Questions: 3Answers: 0
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..
[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..
This discussion has been closed.
Replies
Allan
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.
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
"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
[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
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]
Allan
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.