DataTables / Vue

Vue plugin for DataTables
MIT License
64 stars 12 forks source link

ColReorder does not work correctly when Vue.js Components are used #36

Open DomasWEB opened 1 month ago

DomasWEB commented 1 month ago

It seems that if you use ColReorder + Vue.js components they are not movable with each other. The header moves but the content stays the same.

Findings:

Preview: ezgif-4-ca1a40cb91

<script setup>
const columns = ref([
  {
    data: 'a',
    title: 'One',
    render: '#comp'
  },
  {
    data: 'b',
    title: 'Two Two',
    render: '#comp'
  },
  {
    data: 'c',
    title: 'Three Three Three',
    render: '#comp'
  },
]);

const options = {
  colReorder: true,
};
</script>
<DataTable
      class="display"
      :columns="columns"
      :data="data"
      :options="options"
      ref="table"
    >
      <template #comp="props">{{ props.cellData }} </template>
    </DataTable>

Example: https://stackblitz.com/edit/datatables-net-vue3-reactive-tmmaxz?file=src%2FApp.vue

P.S. I am writing this issue in the https://github.com/DataTables/Vue/ because I think the issue might be in "DataTables/VueJS" side not in "DataTables/ColReorder". Let me know if I should move it to "DataTables/ColReorder"

AllanJard commented 1 month ago

Thank you for raising this. It probably needs this action to happen on the columns-reordered event as well.

I'm tied up with a few other things at the moment, so if you are able to try that (simplying adding columns-reordered.dt to the on event string should do it, and send a PR, that would be most welcome.

DomasWEB commented 1 month ago

@AllanJard the event is called but the result is exactly the same. Added console.log to make sure everything is deleted.

Screenshot 2024-07-18 at 13 45 30

Console: Screenshot 2024-07-18 at 13 46 05

Any other suggestions I could try?

Thank you

AllanJard commented 1 month ago

Off the top of my head (which is going to be questionable, since I thought that might do the job alone) - you might need to invalidate the data ( https://datatables.net/reference/api/rows().invalidate() ). However, I think I'm going to need to set some time aside at some point to sit down and think this through.

DomasWEB commented 1 month ago

@AllanJard did some more testing with rows().invalidate().draw() but it did not change anything.

If you have any more ideas for me to test let me know. Otherwise I'll wait for your comment, thank you