# Expand Table button shows wrong table

**URL:** https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969
**Category:** Bug
**Tags:** size-s
**Created:** [June 24, 2022, 12:59am UTC](https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969 "2022-06-24T00:59:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![burke](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/burke/32/4211_2.png) [@burke](https://meta.discourse.org/u/burke)
#### Post date: [June 24, 2022, 12:59am UTC](https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969/1 "2022-06-24T00:59:56Z")

</div>

I recently created a post that contained a couple of tables. The first table looked like this:

| Drug | Example prescription(s) | Feature(s) |
| --- | --- | --- |
| abacavir | 300 mg mg by mouth twice daily  
600 mg by mouth once daily | Multiple templates for the same drug |
| abacavir / dolutegravir / lamivudine | 1 tablet by mouth daily | Combination drug |
| levonorgestrel | One tablet by mouth as soon as possible within 72 hours of unprotected sexual intercourse or suspected contraceptive failure | Free text dosing instructions |
| paracetamol | 500 mg every 6 hours as needed for pain | As needed dosing |

There was some intervening text …

with

- list
- and
- other
- stuff

…and then another (large) table like this:

| concept | drug | template |
| --- | --- | --- |
| Abacavir | Abacavir 300 mg tablet | 

```json
{
  dosingType: "org.openmrs.SimpleDosingInstructions",
  instructions: {
    dose: 300,
    doseUnits: "161553AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* mg */
    route: "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* oral */
    frequency: "160858AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* twice daily */
  }

```

 |
| Abacavir | Abacavir 300 mg tablet | 

```json
{
  dosingType: "org.openmrs.SimpleDosingInstructions",
  instructions: {
    dose: 600,
    doseUnits: "161553AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* mg */
    route: "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* oral */
    frequency: "160862AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* once daily */
  }
}

```

 |
| Abacavir / dolutegravir / lamivudine | Abacavir/dolutegravir/lamivudine 600/50/300 tablet | 

```json
{
  dosingType: "org.openmrs.SimpleDosingInstructions",
  instructions: {
    dose: 1,
    doseUnits: "1513AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* tablet */
    route: "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* oral */
    frequency: "160862AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* once daily */
  }
}

```

 |
| Levonorgestrel | Levonorgestrel 1.5 mg tablet | 

```json
{
  dosingType: "org.openmrs.FreeTextDosingInstructions",
  instructions: {
    text: "One tablet by mouth as soon as possible within 72 hours of unprotected sexual intercourse or suspected contraceptive failure"
  }
}

```

 |
| Paracetamol | Paracetamol 500 mg tablet | 

```json
{
  dosingType: "org.openmrs.SimpleDosingInstructions",
  instructions: {
    dose: 500,
    doseUnits: "161553AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* mg */
    route: "160240AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* oral */
    frequency: "162249AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", /* every 6 hours */
    asNeeded: true,
    asNeededCondition: "pain"
  }
}

```

 |

The JSON templates got cropped without the ability to horizontally scroll them or the table. Fortunately, when hovering over the second table, the spiffy new “Expand Table” button appeared. Unfortunately, when I clicked on the button to expand the second table, it showed an expanded view of the _first_ table. So, I’ve copied the tables into a post here to see if I can recreate the problem on meta.

Sure enough. It looks like the same bug is happening here. Perhaps the problem is because the first table is done with markdown and the second table is done using HTML (in order to embed JSON with syntax highlighting). 😕

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [June 24, 2022, 6:32am UTC](https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969/3 "2022-06-24T06:32:44Z")

</div>

Oh I can see the bug here:

> <https://github.com/discourse/discourse/blob/7d41e980c90c7511f78a7645c51a52ea67a74322/app/assets/javascripts/discourse/app/initializers/post-decorations.js#L159-L164>

We are doing a naive query selector here, so it is **always** picking the first table in the post. Instead it should search for the first table **after** the button that was clicked.

We will get this sorted some time in the next month, thanks for raising.

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [July 6, 2022, 1:47pm UTC](https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969/8 "2022-07-06T13:47:23Z")

</div>

This has been fixed per [DEV: Update expand-table table query by janzenisaac · Pull Request #17347 · discourse/discourse · GitHub](https://github.com/discourse/discourse/pull/17347)

The expected table will now open 🙂 Thanks for raising this!

---

<div class="post-metadata">

### Author: ![isaac](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/isaac/32/235758_2.png) [@isaac](https://meta.discourse.org/u/isaac)
#### Post date: [July 7, 2022, 1:42pm UTC](https://meta.discourse.org/t/expand-table-button-shows-wrong-table/230969/9 "2022-07-07T13:42:05Z")

</div>


