How to access sorted data in the GridJS library in the console after a sort event?

61 Views Asked by At

I'm using the GridJS library to display a data grid on my web page. I've set the sorting option (sort) to true, and now I'm trying to access the sorted data in the browser console after a sorting event.

Here is the complete code snippet, including the data array:

<div id="grid"></div>
<script src="https://unpkg.com/gridjs/dist/gridjs.umd.js"></script>
const data = [
  { email: "[email protected]", name: "John", phoneNumber: "(353) 01 222 3333" },
  { email: "[email protected]", name: "Mark", phoneNumber: "(01) 22 888 4444" },
  { email: "[email protected]", name: "Ener", phoneNumber: "(55) 19 971 2821" },
  { email: "[email protected]", name: "John", phoneNumber: "(353) 01 222 3333" },
  { email: "[email protected]", name: "Mark", phoneNumber: "(01) 22 888 4444" },
  { email: "[email protected]", name: "Ener", phoneNumber: "(55) 19 971 2821" },
];

const grid = new gridjs.Grid({
  pagination: {
    limit: 10
  },
  sort: true,
  columns: ["name", "email", "phoneNumber"],
  data: data,
}).render(document.getElementById("grid"));

// Unfortunately, the 'sort' event doesn't provide direct access to the sorted data
// Here's the issue: in the console, I can't find any event that accesses the sorted data
grid.on('sort', (column, direction) => {
  console.log(`Sorted column: ${column}, Direction: ${direction}`);
  
  // I tried to access the sorted data using grid.config.data, but it doesn't work
  const sortedData = grid.config.data;
  console.log('Sorted data:', sortedData);
  
  // The question is: How can I correctly access the sorted data in the GridJS library in the console?
});

In the console, I can't find any event that provides direct access to the sorted data. How can I correctly access the sorted data in the GridJS library in the console?

0

There are 0 best solutions below