This topic is locked

Set row color with JavaScript

4/27/2020 11:50:55 AM
PHPRunner General questions
A
AlphaBase author

I know how to set the background row color using server-side After Record Processed. The problem is that when I change a field value the row color doesn't change unless I refresh the grid. This is not an acceptable solution. So i want to use JavaScript. Tried this but it's not working.

JavaScript OnLoad event:
var priority = row.getFieldValue("Priority");
if (priority == 'High') {

row.record().css('background', 'red');

}else if (priority == 'Low') {

row.record().css('background', 'blue');

}
What am I missing?

C
cristi 4/27/2020

You can do it in "after record processed" with php simulating a page refresh:

Just add this:

echo '<script>window.parent.location="YOURTABLENAME_list.php?a=return"</script>';


If you want to manipulate the style in javascript I think that you should use "addStyle": https://xlinesoft.com/phprunner/docs/ctrl_addstyle.htm

A
AlphaBase author 4/27/2020

cristi, that doesn't work. It just causes the page to hang.

C
cristi 4/27/2020

Strange...the php refresh with echo works for me in my applications - did you write the YOURTABLENAME with your table name -not alias - exactly like in your browser address bar???

Are you using inline edit/add, edit/add in popup or custom button???

A
AlphaBase author 4/27/2020

The table name and alias are the same so no issue there. The edit occurs in a modal popup. But as soon as I load the page with the grid (it's a child grid in master-detail if that matters) it hangs.

Here's the code:

IF ($data["Priority"] == "High") {

// $record["Priority_css"]='background:#29ba05; color:#ffffff;'; // Note: color:#ffffff = font color

$record["css"]="background:#abfcce;";

}

ELSE IF ($data["Priority"] == "Medium") {

// $record["Priority_css"]='background:#c0e1f7;';

$record["css"]="background:#c0e1f7;";

}

ELSE IF ($data["Priority"] == "Low") {

// $record["Priority_css"]='background:#fffda5;;';

$record["css"]="background:#fffda5;";

}
echo '<script>window.parent.location="wo_task_list.php?a=return"</script>';
C
cristi 4/27/2020



The table name and alias are the same so no issue there. The edit occurs in a modal popup. But as soon as I load the page with the grid (it's a child grid in master-detail if that matters) it hangs.

Here's the code:

IF ($data["Priority"] == "High") {

// $record["Priority_css"]='background:#29ba05; color:#ffffff;'; // Note: color:#ffffff = font color

$record["css"]="background:#abfcce;";

}

ELSE IF ($data["Priority"] == "Medium") {

// $record["Priority_css"]='background:#c0e1f7;';

$record["css"]="background:#c0e1f7;";

}

ELSE IF ($data["Priority"] == "Low") {

// $record["Priority_css"]='background:#fffda5;;';

$record["css"]="background:#fffda5;";

}
echo '<script>window.parent.location="wo_task_list.php?a=return"</script>';



Sorry I should have been explained better:
The php formatting code should be in list page "after record processed" and the

echo '<script>window.parent.location="wo_task_list.php?a=return"</script>';


should be in add/edit page after record added/updated

A
AlphaBase author 4/27/2020

Aahh.. that works, cristi.

Very cool.

Thanks much.

Sergey Kornilov admin 4/27/2020

Just an example of changing the background of one of the records from Javascript. Maybe you can achieve what you looking for without refreshing the page.

var allRecords = pageObj.getAllRecords();

allRecords.forEach( function( ajaxRow, idx ) {

if (idx==2) {

ajaxRow.record().css('background', 'red');

}

});