kang-sw / egui-data-table

MIT License
35 stars 6 forks source link

Generic Types Implementation & Dynamic Columns Numbers #20

Open deft01 opened 1 week ago

deft01 commented 1 week ago

Hello, amazing work !

Was thinking it could be crazy and very usefull if generic types could be implemented instead of static struct definitions, for example serde_json::Value. And thus the possibility to auto adjust the columns number to the elements to display. This way the objets types rendered in the columns could change over time very easily and unpainfully. Since egui actually doesnt have a fully featured TableViewer implementation this could be game changer.

Example

On the fly change these columns types (3 columns in the table) : Vec<Value::String("one"), Value::Bool(true), Value::Number(42)>

To these columns types (4 columns in the table) : Vec<Value::Null, Value::Number(1337), Value::Array([42, 1, 2]), Value::Bool(false)>

deft01 commented 1 week ago

I've implemented an example of generic types implementation and dynamic columns. I will clean a bit the code and make a pull request.

kang-sw commented 1 week ago

I'm not sure I understood that correctly, but if what you mentioned is dynamically typed row data, you can already specify the generic parameter of the Viewer such as Vec<serde_json::Value> then adjust number of the columns in runtime, by customizing trait method implementation.

To clarify this usage, I'd provide some example code of dynamic typing of each cell data. If not, I'd happily look into your PR 😁.

deft01 commented 1 week ago

Yes, I was talking about customizing the trait implementation. I didn't modify the lib code base. It took me a while to figure out how to implement it so I think providing an example about dynamic Row types could be nice. And that's what I intended to do with the PR.