No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    [Solved] v0.15 QTable Specify Width of a Column In A Table for Long Texts With Word Wrap

    Help
    4
    9
    6398
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      snowdrop last edited by snowdrop

      In v0.15 QTable, Is it possible to specify the width of a column in a table if my column has long texts and will just do a “word wrap” functionality wherein excess texts will just go to the next line?

      1 Reply Last reply Reply Quote 0
      • eder.blinga
        eder.blinga last edited by eder.blinga

        Add CSS

        .q-table tbody td {
            white-space: normal;
        }
        
        1 Reply Last reply Reply Quote 0
        • S
          snowdrop last edited by

          @eder-blinga thanks, I’ll try this one later. First, I’ll try to set the width for each column via css.

          1 Reply Last reply Reply Quote 0
          • S
            snowdrop last edited by snowdrop

            @eder-blinga any idea on how could I set the width of columns? I’ve tried adding this code but it won’t work:

            .q-table thead th {
                width: 50px;
            }
            
            .q-table tbody td {
                width: 50px;
            }
            
            1 Reply Last reply Reply Quote 0
            • S
              snowdrop last edited by

              It somehow work using this:

              .q-table thead th {
                  width: 50px;
                  white-space: normal;
              }
              
              .q-table tbody td {
                  width: 50px;
                  white-space: normal;
              }
              

              Still searching on how could I specify only a specific column to have that width.

              1 Reply Last reply Reply Quote 0
              • S
                snowdrop last edited by

                Done. This is what my code looks like:

                <q-td :style="{width: '400px', whiteSpace: 'normal'}" slot="body-cell-address" slot-scope="props" :props="props">
                    {{props.value}}
                </q-td>
                

                I hope it can help others who might face the same problem. thanks.

                1 Reply Last reply Reply Quote 1
                • H
                  hipernova last edited by

                  Hey! I am facing the same problem.
                  Can you post code for whole <q-table>?

                  Also, manipulating column width in previous version was great 😞

                  S 1 Reply Last reply Reply Quote 0
                  • Hawkeye64
                    Hawkeye64 last edited by

                    Here’s some customization I am doing. The first column receives an icon, and the last column has text and background color change. All the columns between are normal. You should be able to see how to customize based on this:

                        <q-table
                          dense
                          color="teal-6"
                          :data="alarms"
                          :columns="columns"
                          row-key="id"
                          :pagination.sync="pagination"
                        >
                          <q-tr slot="body" slot-scope="props" :props="props" @dblclick.native="rowDoubleClick(props.row)" class="cursor-pointer">
                            <q-td key="downloaded" :props="props">
                              <q-icon :name="getDownloadStatusIcon(props)" />
                            </q-td>
                            <q-td
                              v-for="col in props.cols"
                              v-if="col.name !== 'downloaded' && col.name !== 'acknowledgement'"
                              :key="col.name"
                              :props="props"
                            >
                              {{ col.value }}
                            </q-td>
                            <q-td key="acknowledgement" :props="props" :style="ackWhoStyleObject(props.row)" @click.native="onAckWho(props.row)">
                              {{ getAckText(props.row.ackWho) }}
                            </q-td>
                          </q-tr>
                        </q-table>
                    
                    1 Reply Last reply Reply Quote 0
                    • S
                      snowdrop @hipernova last edited by snowdrop

                      @hipernova Sorry for my late reply. Seems that notifications does not work anymore when someone replies on my previous posts.

                      Anyway, I did not customize any code in my QTable, I just added the code above between <q-table> and </q-table> tags.

                      You can change the width, in my example 400px, and specifying the slot in the slot directive by adding body-cell- to your column name. In my case, my column name is address so the slot name became body-cell-address.

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post