bogdancondorachi / kirby-table-field

📈 Table field plugin for Kirby CMS
https://getkirby.com/plugins/bogdancondorachi/table-field
MIT License
36 stars 2 forks source link

Block: headers toggle don't work #8

Open gbdesign2023 opened 8 months ago

gbdesign2023 commented 8 months ago

I have found a small, cosmetic problem: With the setting "headers: false" in the blueprint, the first line is still displayed as a header in the inline editor. In the dialog editor, the display is correct.

  table:
    label: Tabelle
    type: table
    headers: false
screenshot
bogdancondorachi commented 8 months ago

@gbdesign2023 This is more like a missing feature. The headers toggle was more of an experimental for your issue and was added only to the field itself (that's why it works on the drawer and not the preview), also the headers would still appear on your page even if headers: false (for blocks).

I'd say right now it's more of an experimental feature as I could not find a nice way to integrate this and I'm not satisfied with it. Here's my current approach:

We're talking about rendering of the table inside the page, my idea was to alter the toTable method as follows:

// get the field blueprint
$blueprint = $field->parent()->blueprint()->field($field->key());
// return the headers field value
$hasHeaders = $blueprint['headers'] ?? true;
// return the first row if true or an empty array if false
$headers = $hasHeaders ? array_shift($rows) : [];

This translates into the following:

  1. The table array is considered rows
  2. If headers: true (default) headers consider the first row as headers
  3. If headers: false headers return empty and the first row returns to the rows array

And the current problems are:

  1. $field->key() returns the field name as lowercase and the headers cannot be returned if the field name is tableSecond for example
  2. I could not find a way to access the block field blueprint as I was in a rush to release this today (that's why it does not work in the block)

At this point, I don't know exactly what would even be the best approach to this feature or if I'm looking at it the right way. Some thoughts regarding this matter would be appreciated.

gbdesign2023 commented 7 months ago

Perhaps I have created an unnecessary complication... My problem was the missing "thead" in the previous plug-in. I had created a temporary solution for this in the template. Today I have removed this temporary solution and can use "thead" as in your template. If I don't need a "thead", I can solve this individually, for example with a toggle field in the table options. I assume that 99% of other users need a "thead" for tables. Instead of adding new functions, it would be better to concentrate on the core functions of a table.

bogdancondorachi commented 7 months ago

This feature is still welcomed but would stay as 'experimental' for now until I can find a good balance on how it works.

@gbdesign2023 Would be nice to share your progress on how you've been able to fix your issue after the last update and some panel shots/video on how are you currently using it. It would help me to better understand it's purpose. :)