iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
803 stars 51 forks source link

Embed table in Django Template #540

Closed faultylee closed 4 months ago

faultylee commented 5 months ago

Hi, thanks for creating this great add-on for Django.

I'm trying to have the Table display inside my existing base.html template. I prefer not having to construct that in Page, but insert the table as a block in the template. Is that something that is supported? I can't find any information around this, not in existing issues or from google search.

boxed commented 5 months ago

Inside base.html? You mean on every page?

faultylee commented 5 months ago

No, I wanted to show table in one of the view, and that view loads a Django template that extends on my own base.html. If this works, I would want to do that for multiple views to display diff table, but having the same set of header/footer and navbar...etc

faultylee commented 5 months ago

The alternative I have in mind is to put the table in an iframe of my view

boxed commented 5 months ago

Here's the docs for this: https://docs.iommi.rocks/en/latest/legacy_fbv.html

The ajax dispatch part especially you will want to read I think. I've had someone read that page and stop at the first section and then the table filters don't work. The handle_dispatch part is what will make that work.

But in general the easier and nicer way is to create your own Style (https://docs.iommi.rocks/en/latest/styles.html#creating-a-custom-style) where you give iommi your base.html, and then every iommi view after that will render cleanly inside your base.html so all examples will transfer from the docs into your site with proper styling etc.

faultylee commented 5 months ago

Nice, I didn't know what FBV was, and also didn't realized I can pass template into style, I kept thinking it was more CSS related. I'll give it a try for the next few days. Thanks!

boxed commented 5 months ago

Yea, Style in iommi is a lot more than CSS classes, although that's most of what you want to do in there. It's a system to apply default configuration to your entire project based on certain rules.

The iommi philosophy is that good defaults should be shipped with iommi, but also that you should easily be able to configure what good defaults mean to your specific project too. We don't want the config in iommi to be special, only reasonable defaults.

faultylee commented 4 months ago

Legacy FBV works for me, exactly what I needed and I don't need filtering for now, so no ajax issue. Basically I'm trying to do a parent + children view. I'll explore Custom Style when I'm done with the basics and want to move on to handle more complex use cases.

Thank you for the support and responses. I'll close the issue now.

boxed commented 4 months ago

Cool. I think you'll find that defining your own custom Style will lead to the docs making much more sense :P