Topic: Datatable select single row

alana_vue free asked 3 years ago


Hello, I am using the datatable component and I want to select a single row only -not multiple ones. I am following the documentation and it's my understanding by defining multi as false it should work but in reality I see no changes. Your promptly assistance is greatly appreciated

Expected behavior Being capable of selecting a single row, when the user selects another row the previous one must be unselected

Actual behavior The component is always selecting as many row as the user clicks

Resources (screenshots, code snippets etc.)


Mikołaj Smoleński staff commented 3 years ago

Did you try to remove multi prop from the element? I just checked it and it works correctly.

Keep coding,  Mikołaj from MDB


alana_vue free commented 3 years ago

I am not using the multi prop. Here the props I am using: Any other clue?Thanks

  <MDBDatatable
    :dataset="dataset1"
    :hover="true"
    :edit="false"
    selectable

  />

Mikołaj Smoleński staff commented 3 years ago

@alana_vue I checked it again and to be honest, I still don't see any possibility that it won't work properly. Here's the code with if statement that runs after checkbox change:

const handleCheckboxChange = (rowId, rowChecked) => {
  if (!props.multi && rowChecked === false) {
    data.value.rows.forEach((row) => {
      if (row.mdbId !== rowId) {
        row.selected = false;
      }
    });
  }

  emitSelectedValues();
  updateAllSelectedCheckbox();
};

As you can see if multi prop is false (which in fact is a default value) and row is not checked, then all rows will become unchecked. Can you share some more code including dataset?

Keep coding,  Mikołaj from MDB


alana_vue free commented 3 years ago

@Mikołaj Smoleński thanks for your reply but it is not working properly on my end. However, I notice that it does not work when the dataset is updated from an API. I did a test with 2 identical datasets, one using an API and another one static, and in the static case it works as intended. In the case of the API it does not work. I also tested the api case using both a ref variable and a reactive variable. Here below the data set I'm using:

const dataset1 = { columns: [ { label: "id", field: "id", sort: true, left: 0 }, { label: "name", field: "name", sort: true, left: 0 }, { label: "scope", field: "scope", sort: true, left: 0 }, { label: "history", field: "history", sort: true, left: 0 }, { label: "created_at", field: "created_at", sort: true, left: 0 }, { label: "updated_at", field: "updated_at", sort: true, left: 0 }, { label: "casetag", field: "casetag", sort: true, left: 0 }, { label: "type", field: "type", sort: true, left: 0 }, { label: "ensemble_type", field: "ensemble_type", sort: true, left: 0 }, ],

  rows: [
    {
      id: 1,
      name: "Nacho Test",
      scope: "PUBLIC",
      history: "",
      created_at: "2021-07-07T23:28:50.196523Z",
      updated_at: "2021-07-07T23:28:50.196523Z",
      casetag: "",
      type: "HF",
      ensemble_type: "NONE",
      mdbIndex: 0,
      selected: false,
    },
    {
      id: 2,
      name: "new case",
      scope: "PUBLIC",
      history: "test 2",
      created_at: "2021-08-08T20:15:30.601243Z",
      updated_at: "2021-08-08T20:15:30.601243Z",
      casetag: "",
      type: "SPE1",
      ensemble_type: "NONE",
      mdbIndex: 1,
      selected: false,
    },
  ],

};

Mikołaj Smoleński staff commented 3 years ago

Ok, now I can see the issue. We will try to fix it as soon as possible.

Keep coding,  Mikołaj from MDB


alana_vue free commented 3 years ago

Thank you, is there any workaround in the meantime?


Mikołaj Smoleński staff commented 3 years ago

Unfortunately, I don't see a way around this problem, but we'll do our best to fix it in the next UI KIT version (release 04.10).

Keep coding,  Mikołaj from MDB


alana_vue free commented 3 years ago

Hello! I updated the project to use the latest mdb-vue release and it looks to me that the issue was not addressed. Could you please confirm this and also let me know when this will be solved ? Thank you


Mikołaj Smoleński staff commented 3 years ago

We fixed the issue. Are you sure that you have installed the latest 1.4.0 version?

Keep coding,  Mikołaj from MDB



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Vue
  • MDB Version: MDB5 1.0.0
  • Device: PC
  • Browser: Chrome
  • OS: Windowns10
  • Provided sample code: No
  • Provided link: No