Page 1 of 2

Highlighting Specific Records

Posted: 2013-02-20 18:48
by Tekno Venus
I'm not sure if this is possible, but I would like to give it a try :)

In my database I have a drop down list with a couple of different options in. My goal here is to automatically highlight all the rows in the table with one option from the list selected.

For example, if the drop down list had 2 values, yes and no, I would like any data that has a Yes value to have a red font colour which can be done in HTML.

The only way I can think of doing is via Javascript, but I'm not sure. I think the best way to do this here would be to customize the tablename_footer or tablename_footer hook for the table and to insert some javascript code for colourizing the specific records. I can do the JS (something like document.getElementById('').style.color="red";), but I'm not sure how I could check for a specific value, ie. yes or no.

Does anyone have any ideas on how to do this?

Thanks,
Stephen

Re: Highlighting Specific Records

Posted: 2013-02-21 10:23
by pgkounelas
Stephen, This is the code you need, from appginni tutorials.

Code: Select all

function tablename_init(&$options, $memberInfo, &$args){	
	// modify the status field of the table view query to display 'no' invoices in bold red
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`tablename`.`fieldname`'){
				$options->QueryFieldsTV['IF(`tablename`.`fieldname`=\'yes\', \'<b style="color: green;">YES</b>\', IF(`tablename`.`fieldname`=\'no\', \'<b style="color: red;">NO</b>\', `tablename`.`fieldname`))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
			return TRUE;
	}

Re: Highlighting Specific Records

Posted: 2013-02-21 18:30
by Tekno Venus
Thanks, I will try that when I get a chance!

Where did you find this? Or did you make this yourself?

Stephen

Re: Highlighting Specific Records

Posted: 2013-02-21 18:44
by pgkounelas
This piece of code I found here:
http://bigprof.com/appgini/free-open-so ... plications
the page is "Download free open source web applications" click on the link "Download Simple Invoicing".
and in the hooks folder the file invoices.php have all the code.

Re: Highlighting Specific Records

Posted: 2013-02-21 19:35
by Tekno Venus
Ahhh, thank you very much.

I am currently working on other stuff, but will try this ASAP. Thanks for the code! :)

Re: Highlighting Specific Records

Posted: 2013-02-22 20:26
by Tekno Venus
This works great! Thank you very much!!

Re: Highlighting Specific Records

Posted: 2013-02-23 21:02
by Tekno Venus
Ok, I am now having an issue and require help.

The original code:

Code: Select all

function tablename_init(&$options, $memberInfo, &$args){   
   // modify the status field of the table view query to display 'no' invoices in bold red
      $oldArray=$options->QueryFieldsTV;
      $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
         if($field=='`tablename`.`fieldname`'){
            $options->QueryFieldsTV['IF(`tablename`.`fieldname`=\'yes\', \'<b style="color: green;">YES</b>\', IF(`tablename`.`fieldname`=\'no\', \'<b style="color: red;">NO</b>\', `tablename`.`fieldname`))']=$caption;
         }else{
            $options->QueryFieldsTV[$field]=$caption;
         }
      }
         return TRUE;
This code works fine to replace the field text with a specific string, for example <b>Yes</b>. Where the field has the value of Yes, it will be replaced with <b>Yes</b>

Now, what I want to do is wrap the <b></b> tags around EXISTING data. To explain, the table already has data in. What I want it to do is when one field says yes, make the data already in the other field bold.

I am close to this with this code:

Code: Select all

// modify the status field of the table view query to display 'Windows Update' drivers in bold red
      $oldArray=$options->QueryFieldsTV;

	  
      $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
         if($field=='`SaD`.`info`'){
            $options->QueryFieldsTV['IF(`SaD`.`source`="Windows Update", "<b>Yes</b>",  `SaD`.`info` )']=$caption;
         }
		 else{
            $options->QueryFieldsTV[$field]=$caption;
         }
      }
This code checks to see if the data in SaD.source says Windows Update. If it does it replaces the data in SaD.info with Yes. However, what I want to do is wrap the existing data in the SaD.info field with <b> tags so it makes that data bold.

I tried this but it does not work:

Code: Select all

// modify the status field of the table view query to display 'Windows Update' drivers in bold red
      $oldArray=$options->QueryFieldsTV;

	  
      $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
         if($field=='`SaD`.`info`'){
            $options->QueryFieldsTV['IF(`SaD`.`source`="Windows Update", "<b style=color:red>"SaD.info"</b>",  `SaD`.`info` )']=$caption;
         }
		 else{
            $options->QueryFieldsTV[$field]=$caption;
         }
      }
To give a worked example, if SaD.source said "Windows Update" and SaD.info said "Windows OS Kernel Driver", I want to make the "Windows OS Kernel Driver" bold.

Does this make sense? Can anyone help? I have been trying for ages to get this to work!!!

Thanks to anyone who can help
Stephen

Re: Highlighting Specific Records

Posted: 2013-02-25 08:28
by a.gneady
Try this as the second parameter to the IF function in your code:

Code: Select all

CONCAT("<b style=color:red>", `SaD`.`info`, "</b>")

Re: Highlighting Specific Records

Posted: 2013-02-25 18:49
by Tekno Venus
THANK YOU AHMAD!!!

That worked perfectly! Issue solved and thanks again!

Stephen

Re: Highlighting Specific Records

Posted: 2013-09-25 18:41
by selectsteel
I to have been trying to get somthing like this to work for some time. I want to change the color of the text in a column if it has a value in it and I would actually like to change the color of the cell if possible.
I have tried a hundred variations on the code below with no success.

Code: Select all

  options->QueryFieldsTV['IF(`tablename`.`column` != "" ,  CONCAT('<font color="red">' , `tablename`.`column` , '</font>'))']=$caption;
any help would be appreciated.

Re: Highlighting Specific Records

Posted: 2013-10-12 14:45
by a.gneady
You need to escape the single quotes inside the index as follows:

Code: Select all

options->QueryFieldsTV['IF(`tablename`.`column` != "" ,  CONCAT(\'<font color="red">\' , `tablename`.`column` , \'</font>\'))']=$caption;

Re: Highlighting Specific Records

Posted: 2017-08-21 17:37
by D Campbell
how do you add more than two records to that? I only got two of records from drop down menu to work?

Re: Highlighting Specific Records

Posted: 2017-08-21 17:40
by D Campbell
also, when one of drop menu list is selected, and i would like to have entire row in color on the background as well.

Re: Highlighting Specific Records

Posted: 2017-08-21 18:24
by D Campbell
Finally got it figured out.... it was just to add one more parenthesis at end of statement and go on when you need more than two records on the same column.

** change "tablename" and "fieldname" to your table name and column name of the table you created. Replace three names (John Doe, Jane Doe and Baby Doe) to whatever you created under the column or list under drop down menu or checklist or whatever. **

example:

$options->QueryFieldsTV['IF(`tablename`.`fieldname`=\'john doe\', \'<b style="color: red;">John Doe</b>\', IF(`tablename`.`fieldname`=\'jane doe\', \'<b style="color: blue;">Jane Doe</b>\', IF(`tablename`.`fieldname`=\'baby doe\', \'<b style="color: green;">Baby Doe</b>\', `tablename`.`fieldname`)))']=$caption;

Re: Highlighting Specific Records

Posted: 2019-11-11 11:51
by Ionut Bocanet
Dear Sirs,

I need a little help. I used the below code to highlight a record based on a Status Value. It is working fine in Details View of the Parent Records, but it is not working at child level.

<script>
$j(function(){
$j('.Agenda_Item_Action_Log-Status').each(function(){
var Status=$j(this).text();
if(Status=='Completed'){
$j(this).parents('tr').addClass('success');

}
if(Status=='In Progress'){
$j(this).parents('tr').addClass('warning');
}

if(Status=='Not Started'){
$j(this).parents('tr').addClass('primary');

}
})

It is possible to help me to have the formatting also on the children records.

In example 1 you can see how it appears in Details View and proves the code working.

In example 2 i want to achieve the same thing.


Thank you in advanced

Re: Highlighting Specific Records

Posted: 2019-11-11 18:31
by pbottcher
Hi,

where do you have the code you posted?

Re: Highlighting Specific Records

Posted: 2019-11-12 09:39
by onoehring
Hi Ionut,

the problem might be that the details are rendered by ajax - maybe after the page code has been loaded already.
You may try the jquery ready event and run your markup-js-code once the page is actually ready (ajax done).

Olaf

Re: Highlighting Specific Records

Posted: 2019-11-12 12:30
by Ionut Bocanet
pböttcher wrote:
2019-11-11 18:31
Hi,

where do you have the code you posted?
Hello Sir,

This code i took it from the course supplied by Appgini in the Udemy website.

Re: Highlighting Specific Records

Posted: 2019-11-12 12:46
by onoehring
Hi Ionut,

maybe check out these old posts of mine:
viewtopic.php?f=2&t=3104&p=10371#p10381
viewtopic.php?f=2&t=3194&p=10935#p10935
and
viewtopic.php?f=7&t=3280&p=11325#p11322

I think these might help. In the first link I am adding something to the details, using a setInterval function - not as good as the ready event probably, but it works. I suppose by rewriting the code you will be able to get what you need.

Olaf

Re: Highlighting Specific Records

Posted: 2020-11-28 17:00
by federico
Ionut Bocanet wrote:
2019-11-11 11:51

<script>
$j(function(){
$j('.Agenda_Item_Action_Log-Status').each(function(){
var Status=$j(this).text();
if(Status=='Completed'){
$j(this).parents('tr').addClass('success');

}
if(Status=='In Progress'){
$j(this).parents('tr').addClass('warning');
}

if(Status=='Not Started'){
$j(this).parents('tr').addClass('primary');

}
})
Hi! Did you fix it? I have the same problem for a children table. I wrote the code in footer-extra.php file
tks

Re: Highlighting Specific Records

Posted: 2020-11-28 20:51
by pbottcher
Hi,

you can see the the code in

viewtopic.php?f=2&t=4025&sid=19c71490cb ... 4d9#p15525

just replace the code in the wait_for call with your code

Re: Highlighting Specific Records

Posted: 2020-12-01 15:28
by federico
Hi

first of thanks for your answer. I'm sorry but I'm little noob on this. I'm trying the below code where the children table is Agenda and the parent table is Clienti:

<script>
$j(function wait_for(data,callback,time=1000) {
$j('.Clienti-Agenda-Stato').each(function(){
var Stato = $j(this).text();
if(Stato == 'Attesa Azione Cliente'){
$j(this).parents('tr').addClass('warning');
}
if(Stato == 'Attesa Azione Tecnoplastic'){
$j(this).parents('tr').addClass('danger');
}
if(Stato == 'Attesa Azione Commerciale'){
$j(this).parents('tr').addClass('success');
}
})
})
</script>

Re: Highlighting Specific Records

Posted: 2020-12-01 22:17
by pbottcher
hmmm,

try

Code: Select all

<script>
$j(function() {
	function wait_for(data,callback,time=100) {
		if($j(data).length != 0) {
			callback();
			return;
		}
		else {
			setTimeout(function() {
				wait_for(data,callback, time);
			}, time);
		}
	}
	wait_for('.table-striped',function() {
		$j('.Clienti-Agenda-Stato').each(function(){
			var Stato = $j(this).text();
			if(Stato == 'Attesa Azione Cliente'){
				$j(this).parents('tr').addClass('warning');
			}
			if(Stato == 'Attesa Azione Tecnoplastic'){
				$j(this).parents('tr').addClass('danger');
			}
			if(Stato == 'Attesa Azione Commerciale'){
				$j(this).parents('tr').addClass('success');
			}
		})
	})
})
</script>

Re: Highlighting Specific Records

Posted: 2020-12-02 08:54
by federico
I'm sorry. It doesn't work. I'm copying it on footer-extra file right?
I also try on another database, but nothing happen.
I noticed that if I try to open an attached file on the record of the sub-table, the file is empty, meanwhile if I open the file directly in that table (from the link in homepage) it works. Could depends on the appgini update? Or is this just another problem?

Re: Highlighting Specific Records

Posted: 2020-12-02 11:13
by pbottcher
Hi,

the file openening is another problem, not related to this question.

For this question.
Are you sure you have the correct Class you are looking at? Is "Clienti-Agenda" the child table name and "Stato" the fieldname? Is the Text exactly what the $j(this).text() returns?

Maybe you can post a screenshot of the definitions.

The code itself works. I tested it on my testsystem.