Highlight row based on count of field in other table.
Highlight row based on count of field in other table.
MickB
Posts: 103Questions: 25Answers: 2
Hi,
What is the simplest way to highlight a row, only if it doesn't have related rows in another table?
Eg,
Losses Datatable for losses db table.
Rows highlighted if there is not a record in the recorded_faults table with a matching loss id.
I have the highlighting bit:
"createdRow": function( row, data, dataIndex ) {
if ( data.recorded_faults.loss_id == null ) {
$(row).addClass( 'important' );
}
}
I am using Editor and the PHP Library.
Mick
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi Mick,
That you have looks fairly good to me - does that not work for you? The one thing I can see that wouldn't work with the above is that it triggers on
createdRow
only, which will only fire once in the lifetime of a row. You would need to userowCallback
if you wanted it to run once the data has been updated (for example, you might use Editor to assign a related row, thus the highlight should be removed, and the inverse).Regards,
Allan
At the moment, it is working but pulls back multiple rows from the losses table, if there are multiple records in the recorded_faults table.
I guess the problem is my join:
Mick
Hi Mick,
Can there be multiple
recorded_faults
for a singlelosses
record? If so, the one-to-many join is going to be a better way to structure the query.Regards,
Allan
Yes, nearly got this now.
I was getting this error:
"FatalErrorException in Bootstrap.php line 53:
App\Libraries\DataTables{closure}(): Failed opening required '/var/www/html/selection/app/Libraries/DataTables/Editor/MJoin.php' (include_path='.:/usr/share/pear:/usr/share/php')"
(from Laravel)
I had to rename Mjoin.php to MJoin.php to resolve this. Is there a reason why it had a lower case J?
Mick
Yes, the auto loader uses the capitalisation of the letters to reflect the path name.
Editor\MJoin
would be found in theEditor/M/Join.php
path, whileEditor/Mjoin
(which the documentation should always refer to) will be inEditor/Mjoin.php
.Allan
Not sure I understand that.
In my Editor directory I have:
Editor.php
Join.php
Mjoin.php
In Mjoin.php.
I now have this:
I get the error:
Datatables warning: table_id = generic_table SQLSTATE[42522]: Column not found: 1054 Unknown column 'losses.loss_id' in 'field list'.
I can't see where it is getting the 'losses.loss_id' from?
Just trying to debug.
Error comes from line 465 Join.php.
Looking at $stmt
table is losses as losses
_field(0) is losses.loss_id as dteditor_pkey
This is where It comes from;
->get( $dteTableLocal.'.'.$joinField.' as dteditor_pkey' )
dteTableLocal = losses
joinField = loss_id
So, maybe I have the joinField wrong somewhere.
Swapped the link round:
previously:
->link( 'recorded_faults.loss_id', 'losses.id' )
now:
->link( 'losses.id', 'recorded_faults.loss_id' )
Looks like it is working.
I guess that my loss_id field is named incorrectly anyway, my primary keys should me tablename_id.
Yes, works now!
Good to hear you've got it working now :-)
Allan