Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get elements from board as JSON #64

Open
thijsd opened this issue Sep 17, 2019 · 7 comments
Open

get elements from board as JSON #64

thijsd opened this issue Sep 17, 2019 · 7 comments

Comments

@thijsd
Copy link

thijsd commented Sep 17, 2019

It would be nice to have a function to export the elements to JSON.
Using this it should be easier to send the elements to ajax for example.

@marcosrocha85
Copy link
Contributor

This is nice. I had to keep jKanban data in a var to save on database. Having a function to export kanban to json will make that simpler.

@ronaklalwanii
Copy link

Can I look into it?

@marcosrocha85
Copy link
Contributor

Can I look into it?

For sure. Pull requests are always welcome.

@marcosrocha85
Copy link
Contributor

marcosrocha85 commented Jul 12, 2021

This is very tricky. We have two approaches according to my knowledge.
🚀 1. Create an array attribute and change it on addElement, addBoards, removeElement and removeBoard calls to keep it even with DOM.
or
🎉 2. Read jKanban DOM and output a JSON.

I would like to vote which you guys think it's better.

@CrashLaker
Copy link

i think approach 1. could have some potential inconsistency when the user could be frantically draging the boxes here and there.

therefore i consider approach 2 more trustworthy.

this could help

image

 methods: {
        renderJSON(){
            const obj = this.$refs.demo2
            let boards = []
            obj.querySelectorAll('.kanban-board').forEach(el => {
                let items = []
                el.querySelectorAll('.kanban-item').forEach(i => {
                    items.push({
                        title: i.innerHTML,
                    })
                })
                boards.push({
                    id: el.getAttribute('data-id'),
                    title: el.querySelector('.kanban-title-board').innerHTML,
                    items,
                })
            })
            return boards
        }
    },

image

@DamienBitrise
Copy link

DamienBitrise commented Jun 13, 2022

I think this needs to be updated to return the name of the item not the HTML

methods: {
        renderJSON(){
            const obj = this.$refs.demo2
            let boards = []
            obj.querySelectorAll('.kanban-board').forEach(el => {
                let items = []
                el.querySelectorAll('.kanban-item').forEach(i => {
                    items.push({
                        title: i.childNodes[1].innerHTML,
                    })
                })
                boards.push({
                    id: el.getAttribute('data-id'),
                    title: el.querySelector('.kanban-title-board').innerHTML,
                    items,
                })
            })
            return boards
        }
    },

@luxiusmx
Copy link

luxiusmx commented Apr 26, 2023

I hope it helps, with this I rather get the id's since with that I can get everything else from the database

function renderJSON() {
    const obj = document.querySelector('#div_jkanban_id'); // EDIT YOUR DIV ID
    let boards = [];
    obj.querySelectorAll('.kanban-board').forEach(el => {
        let items = [];
        el.querySelectorAll('.kanban-item').forEach(i => {
            items.push({
                element_id: i.getAttribute('data-eid'),
            })
        })
        boards.push({
            board_id: el.getAttribute('data-id'),
            items,
        })
    })
    return JSON.stringify(boards);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants