Selecting Items in Quasar Data Tables Externally



  • I have a data table that has checkboxes as a selection mechanism. There is a button outside the datatable which will automatically select an item from the table. When I push this button with no prior selection it works fine but when pushing this button after another selection has been made I get the following error:

    [Vue warn]: Duplicate keys detected: ‘1031’. This may cause an update error.

    found in

    —> <QTable>
    <QCard>
    <QSlideTransition>
    <QCollapsible>
    <QItem>
    <DEVICES> at src\components\devices.vue
    <QPageContainer>
    <QLayout>
    <LayoutDefault> at src\layouts\default.vue
    <Root>

    The code I have is shown below:

    <q-btn
      @click= selectPrime()>
    </q-btn>
    <q-card flat>
      <q-table
        :columns="devices_cols_sample"
        :data="devices_sample"
        :filter = "filter"
        :separator="separator"
        row-key="id"
        color="positive"
        :selection="selection"
        :selected.sync="selected"
      >
      </q-table>
    </q-card>
    

    The table columns are defined like so:

      devices_cols_sample: [
        {
          label: 'GUID',
          name: 'deviceGuid',
          width: '200px',
          field: 'guid',
          type: 'string',
          filter: true
        }
      ]
    

    And the data is:

      devices_sample: [
        {
          guid: 'SP-779',
          id: 1013
        },
        {
          guid: 'SP-780',
          id: 1031
        }
      ]
    

    The method I am using to select an item from the table (external to the table) is the following:

    selectPrime(){
      this.selected[0].id = 1031
    }
    

    Is there a better way of selecting a checkbox from a DataTable outside of the DataTable? Is this perhaps a bug in Quasar?
    Shouldn’t any changes to the selected variable happen simultaneously inside the dataTable. It seems that the new value is being checked but the old value isn’t clearing. If this is a bug, is there workaround?