Retrieve the table titles in order to display them as labels

Retrieve the table titles in order to display them as labels

AlignFAlignF Posts: 3Questions: 2Answers: 0

Hello,
Is it possible to automatically retrieve the table titles in order to display them as labels in the creation and edition form, as well as in the bubbles?

<table> <thead> <tr> <th>Número de orden</th> <th>Cantidad</th> </tr> </thead> </table>

  fields: [
    {
      label: "order_number:",
      name: "order_number",

    },
    {
      label: "quantity:",
      name: "quantity",
    },
    ]

Indeed, with each modification, it must be renamed in two places, moreover my translations are done via PHP in the header of my table

Thank you

Answers

  • rf1234rf1234 Posts: 2,444Questions: 78Answers: 353
    edited April 25

    You can use jQuery for this or the api like in here:

    ....
    label: $( yourTable.column("yourColSelector").header() ).html() + ":",
    name: "order_number"
    

    I would assign ids to your <th> tags and use them as col selectors.

    <table> 
        <thead> 
            <tr> 
                <th id="orderNumber">Número de orden</th> 
                <th id="quantity">Cantidad</th> 
            </tr> 
        </thead> 
    </table>
    
    fields: [
      {
        label: $( yourTable.column("#orderNumber").header() ).html() + ":",
        name: "order_number",
     
      },
      {
        label: $( yourTable.column("#quantity").header() ).html() + ":",
        name: "quantity",
      },
      ]
    
  • rf1234rf1234 Posts: 2,444Questions: 78Answers: 353
    edited April 25

    if you do what I suggested above you'll probably get this error:

    Usually the Editor configuration runs before the Data Table's configuration because Editor is being referred to in the Data Table configuration (e.g. for the buttons). Hence you can't reference your Data Table in the Editor configuration.

    So jQuery is the best and simplest option. Since your HTML is around prior to any kind of Editor and Data Table configurations it should work.

    <table id="myTable">
        <thead>
            <tr>
                <th id="orderNumber">Número de orden</th>
                <th id="quantity">Cantidad</th>
            </tr>
        </thead>
    </table>
    
    fields: [
      {
        label: $("#myTable th#orderNumber").html() + ":",
        name: "order_number",
      
      },
      {
        label: $("#myTable th#quantity").html() + ":",
        name: "quantity",
      },
      ]
    
Sign In or Register to comment.