1

I am populating a table with objects received from a JSON array generated by a remote PHP file:

 <tr ng-repeat="data in filtered = (list | filter:search | orderBy : predicate :reverse) | startFrom:(currentPage-1)*entryLimit | limitTo:entryLimit">
                    <td>{{data.material_number}}</td>
                    <td>{{data.service_number}}</td>
                    <td>{{data.ordered}}</td>
                    <td>{{data.quantity}}</td>
                    <td>{{data.pending}}</td>
                    <td>{{data.unit}}></td>
                    <td>{{data.description}}</td>
                    <td>{{data.cost}}</td>
                    <td>{{data.net}}</td>

                    <td><a href="edit_po_item.php?id={{data.id_po}}" class="btn btn-info" role="button">Edit</a></td>
                </tr>

Depending on the received values I need to make some design changes, for example, if {{data.pending}} is an integer between 1 and 5 I want to change the cell background color.

How can I convert the text value from {{data.unit}} to a variable that would let me set conditions to change the layout of the table? Thank you in advance.

2 Answers 2

1

I'd do this in CSS and not in PHP, personally...

Change:

<td>{{data.pending}}</td>

To:

<td data-pending-code='{{data.pending}}'>{{data.pending}}</td>

and now you can do stuff like:

<style>
td[data-pending-code="1"] { background: red; }
td[data-pending-code="2"] { background: blue; }
td[data-pending-code="3"] { background: green; }
td[data-pending-code="4"] { background: yellow; }
td[data-pending-code="5"] { background: purple; }
</style>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your proposal, I will test it, but this solution implies to declare all possible values one by one, and I would prefer to have the chance to define filters.
1

you could force the conversion to a number with {{data.pending*1}} and then check for your design. Here's a fiddle showing conversion

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.