survos / SurvosSimpleDatatablesBundle

integrations with simple Datatables
MIT License
4 stars 0 forks source link

[Question] Column fitltering #1

Open Shotman opened 4 months ago

Shotman commented 4 months ago

Hello, I'm looking for a simple datatable solution for symfony, this seems to be the one but there is one thing I can't seem to be able to do, it's column filtering, I've looked at the code from here : https://fiduswriter.github.io/simple-datatables/demos/20-column-filters/ but modifying the javascript from assets/src/controllers/table_controller.js to reflect what's done in the demo doesn't seem to make column filtering work... am I missing something ? Thanks

tacman commented 4 months ago

So the issue is in the rendering. How are you overwriting table_controller?

I should probably allow that controller to be extended, and have the render be a method that can be overwritten.

            import {DataTable} from "../dist/module.js"
            window.dt = new DataTable("#demo-table", {
                perPageSelect: [10, 50, ["All", -1]],
                columns: [
                    {
                        select: 2,
                        sortSequence: ["desc", "asc"]
                    },
                    {
                        select: 3,
                        sortSequence: ["desc"]
                    }
                ],
                tableRender: (_data, table, type) => {
                    if (type === "print") {
                        return table
                    }
                    const tHead = table.childNodes[0]
                    const filterHeaders = {
                        nodeName: "TR",
                        childNodes: tHead.childNodes[0].childNodes.map(
                            (_th, index) => ({nodeName: "TH",
                                childNodes: [
                                    {
                                        nodeName: "INPUT",
                                        attributes: {
                                            class: "datatable-input",
                                            type: "search",
                                            "data-columns": `[${index}]`
                                        }
                                    }
                                ]})
                        )
                    }
                    tHead.childNodes.push(filterHeaders)
                    return table
                }
            })
Shotman commented 4 months ago

Now that you mention it I might be just an idiot... I temporarly changed the code in your vendor buuuut that might not be the right way :/

tacman commented 4 months ago

If you come up with a generalized solution, submit a PR.

If not, there's a way to overwrite the controller with yours.

On Wed, May 29, 2024 at 11:38 AM Shotman @.***> wrote:

Now that you mention it I might be just an idiot... I temporarly changed the code in your vendor buuuut that might not be the right way :/

— Reply to this email directly, view it on GitHub https://github.com/survos/SurvosSimpleDatatablesBundle/issues/1#issuecomment-2137715328, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEXIQLB3KD3YCYDZVXXTNTZEXY7FAVCNFSM6AAAAABIOPAUFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZXG4YTKMZSHA . You are receiving this because you commented.Message ID: @.***>