Table row color

I have a dynamic table that display numerous columns with horizontal scrolling.
I would like to be able to select a row (record) changing the background color, so I can perform horizontal scrolling by easily identifying the record
Is it possible with Wappler?

There are several ways to do it. For example you could create a variable for the selected record id. On click of a row you set the variable and you use a class toggle on the row to set a selected class.

<style>
.selected { background-color: blue; }
</style>
<dmx-value id="selected"></dmx-value>
<table>
  <tr is="dmx-repeat" repeat="sc.data" dmx-on:click="selected.setValue(id)" dmx-class:selected="id == selected.value">
    <td>{{id}}</td>
    <td>{{name}}</td>
  </tr>
</table>
2 Likes

but my table is different

45

Just adjust what Patrick gave for your table.

<!-- SET A STYLE FOR YOUR SELECTED ROW AS A CLASS -->
<style>
  .css_selected { background-color: blue; }
</style>

<!-- EMPTY VARIABLE TO KEEP TRACK OF WHAT ROW IS SELECTED -->
<dmx-value id="ticket_selected"></dmx-value>

<table>
  <thead>
    <tr>
      <td></td>
    </tr>
  </thead>
<!-- TBODY TAG AS REPEAT -->
  <tbody is="dmx-repeat" dmx-generator="bs4table" dmx-bind:repeat="serverconnect_confermati.data.query_confermati" id="tableRepeat1" dmx-state="query_confermati" dmx-sort="sort" dmx-order="dir">
    <tr dmx-on:click="ticket_selected.setValue(id_ticket)" dmx-class:css_selected="id_ticket == ticket_selected.value">
      <td dmx-text="id_ticket" style="font-size: xx-small;"></td>

or if you are using Data Detail then use it instead of the variable

This works only partially, because it is difficult to select a table row

Can you explain what makes it difficult to select?

Because with Safari or Chrome (MAC) with the mouse there is no real place to click to highlight the line
The ideal would be to insert as a first column a micro button to select the row or to be able to click on id_dicket

Sounds like a good idea to me. So just add another column and add the dmx-on:click as well as the dmx-class commands to the button

This is the new column, but how should the code be added?

<tr dmx-class:css_selected="id_ticket == ticket_selected.value">
  <td>
    <a href="javascript:void(0);" class="btn btn-small" dmx-on:click="ticket_selected.setValue(id_ticket)">CLICK ME</a>
  </td>
  <td dmx-text="id_ticket" style="font-size: xx-small;"></td>

However, it works badly and only in white lines

test.mov (2.2 MB)

Try adding !important to the background-color style command so it can override whatever background color is already in the tr
.css_selected { background-color: blue !important; }

I did not know this thing
Perfect now works perfectly
Thank you very much

You might also want to add more classes to the btn such as btn-info or something like that to get some color into it.
Then if you want you can also add more into the style tag such as
.css_selected:hover { background-color: green !important; }

1 Like

Very interesting