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

    QTable updated nested column value

    Help
    3
    7
    594
    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.
    • N
      nededa last edited by

      Hello,
      I’m trying to updated nested column value in QTable. Quasar does allow you to define field property in columns prop as function which computes required value with getter only but how do I update it?

      Example

      const columns = [
          {
            label: 'Client',
            field: row => row.client.name,
          },
        ]
      
        <template v-slot:body-cell="props">
          <td>
              <q-input v-model="props.value"/>
          </td>
        </template>
      

      I realise that I can just use v-if and write v-model myself but since I’m using graphql it would be nice to have some function to do it automatically. Maybe I’m missing something and you can do it out of box with quasar?

      dobbel metalsadman 2 Replies Last reply Reply Quote 0
      • dobbel
        dobbel @nededa last edited by

        @nededa

        You’ll have to update the v-model of the Qtable. All the relevant code is not in your snippet.

        N 1 Reply Last reply Reply Quote 0
        • N
          nededa @dobbel last edited by

          @dobbel
          What do you mean qtable v-model? For non nested columns I can just use props.row[props.col.field] but obviously I can’t do it with nested object. By using props.value just wanted to show parsed value.

          1 Reply Last reply Reply Quote 0
          • N
            nededa last edited by

            If anyone encounters same problem I just ended doing it like this:

            const columns = [
                {
                  label: 'Client',
                  field: row => row.client.name,
                  editField: 'client.name',
                },
              ]
            
                const setRowField = (row, field, newValue) => {
                  const keys = field.split('.')
                  while (keys.length > 1) {
                    row = row[keys.shift()]
                  }
                  row[keys[0]] = newValue
                }
            
              <template v-slot:body-cell="props">
                <td>
                    <q-input :value="props.value" @input="setRowField(props.row, props.col.editField || props.col.field, $event)"/>
                </td>
              </template>
            
            1 Reply Last reply Reply Quote 0
            • metalsadman
              metalsadman @nededa last edited by

              @nededa use q-td ie. <q-td :props="props"><q-input v-model="props.row.client.name"/></q-td>.

              N 1 Reply Last reply Reply Quote 0
              • N
                nededa @metalsadman last edited by

                @metalsadman yeah I think I weren’t clear enough. I meant updating nested object value dynamically. Basically idea is to wrap q-table in a custom component for easy CRUD.

                metalsadman 1 Reply Last reply Reply Quote 0
                • metalsadman
                  metalsadman @nededa last edited by metalsadman

                  @nededa yeah, don’t know what you’re trying to do with the snippet then, anyway use what’s working for you.

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