How to leave field with bold values

Asked

Viewed 175 times

1

Situation I have a table made in html called Payments and in it I have a column called values, I want to leave the fields with values in bold.

Problem: There are collaborators who had value to be paid and others who did not. As I leave only fields with values greater than 0 in bold?

Ideal Scenario: Leave only fields with values greater than 0 in bold.

HTML:

  <table id="data-table-default" class="table table-striped table-bordered">
                    <thead>
                        <tr>

                            <th class="col-xs-1 text-center">
                                @Html.DisplayNameFor(model => model.Salario1)
                            </th>
                            <th class="col-xs-1 text-center">
                                @Html.DisplayNameFor(model => model.Salario2)
                            </th>
                            <th class="col-xs-1 text-center">
                                @Html.DisplayNameFor(model => model.Salario3)
                            </th>


                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model)
                        {
                            <tr>
                                <td class="text-center">
                                    @Html.DisplayFor(a => item.Salario1)
                                </td>
                                <td class="text-center">
                                    @Html.DisplayFor(a => item.Salario2)
                                </td>
                                <td class="text-center">
                                    @Html.DisplayFor(a => item.Salario3)
                                </td>


                            </tr>
                        }
                    </tbody>

                </table>
  • You used <b> and it didn’t work?

  • Yes but if I put b or Strong in any line it paints bold the idea is only when you have a check greater than 0 then it leaves in bold otherwise it does not leave in bold. I don’t know how to put this part into practice!

  • 1

    And you don’t know how to use one if?

  • @Maniero Opa for example would be something like that. if(Meumodel > 0) { <b>Contents</b> }Else{contents} Would that be correct? However I would have to do line by line, I would do in a check only?

  • 1

    That would be about it, now you’re asking something else. There’s even a way to do it in a loop, but you’d have to use a trick since you don’t have one array, then you’d have to create one with the names of the fields. It would also work with a function that abstracts this, would have to call 3 times, but would not have all repetition of code and would not need to create a array. You can even create a new tag to do this in an abstract way. But here we are already talking about another problem other than the question.

  • @Maniero guy helped a lot, thank you very much even managed to do here. Thanks for the info my friend.

Show 1 more comment

1 answer

0


@Thiago Correa, in this case the condition has to be restricted to the field, there would be no way to do a single check to go through the table, because the condition is exclusive of the "field". It has to be made a IF for each field. Through javascript (jQuery), you could solve, but it is not in the scope of the question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.