The ListDataTable component is a versatile tool for displaying tabular data in a list format. It’s designed to be flexible, supporting features like sorting, custom row rendering, and even loading states. Here’s a guide to help you implement it in your React projects.

Basic Usage

To use the ListDataTable, you need to define the column headers and provide a function to build the rows based on your data. Here’s an example of a simple data table:
import ListDataTable from "./path-to-list-data-table-component";
import { RunningText } from "./path-to-running-text-component";

const MyDataTable = () => {
  // Define your columns
  const columns = [
    { flex: 2, child: <RunningText>Name</RunningText> },
    { flex: 1, child: <RunningText>Age</RunningText> },
  ];

  // Build rows from your data
  const dataTableItemBuilder = (dataItem, index) => {
    return {
      key: `row-${index}`,
      children: [
        { child: <RunningText>{dataItem.name}</RunningText> },
        { child: <RunningText>{dataItem.age}</RunningText> },
      ],
    };
  };

  // Your data
  const data = [
    { name: "Alice", age: 30 },
    { name: "Bob", age: 25 },
  ];

  return (
    <ListDataTable
      data={data}
      columns={columns}
      dataTableItemBuilder={dataTableItemBuilder}
    />
  );
};

Handling Clicks

You can also handle row clicks by providing an onClick function. Here’s how you can do it:
<ListDataTable
  data={data}
  columns={columns}
  dataTableItemBuilder={dataTableItemBuilder}
  onClick={(dataItem) => console.log("Row clicked", dataItem)}
/>

Sorting

If you want your list to be sortable, set the sortable prop to true and provide an onSortEnd callback:
<ListDataTable
  data={data}
  columns={columns}
  dataTableItemBuilder={dataTableItemBuilder}
  sortable={true}
  onSortEnd={(oldIndex, newIndex) => console.log(oldIndex, newIndex)}
/>

Customizing Appearance

You can customize the appearance of your table and rows using the itemClassName and tableClassName props:
<ListDataTable
  data={data}
  columns={columns}
  dataTableItemBuilder={dataTableItemBuilder}
  itemClassName="my-custom-row-class"
  tableClassName="my-custom-table-class"
/>

Loading State

Lastly, you can show a loading state by setting the isLoading prop to true. This will display skeleton loaders until your data is ready:
<ListDataTable
  data={data}
  columns={columns}
  dataTableItemBuilder={dataTableItemBuilder}
  isLoading={true}
/>
With these basics, you’re well-equipped to start using the ListDataTable component in your React applications. Happy coding!