Grapesjs: [QUESTIONS] How to change order of categories?

Created on 30 Sep 2019  路  3Comments  路  Source: artf/grapesjs

I saw the changes done by @JuanTincho of adding the "Order" attibute but I was able of adding it only on new categories created.
I started from the "GrapesJs-Preset-Webpage".
Is there a way of changing the Order after the initial render?
This is how I add a new category by adding a new block.

editor.BlockManager.add('Cards', {
  label: 'Cards',
  content: '
Put your content here
', category:{ label: 'MyCategory', order: 1, open: true }, attributes: { title: 'Insert Cards', class: 'fa fa-cube' } });

Most helpful comment

but I was able of adding it only on new categories created.

you can do this on all blocks by leveraging from getAll function. more on this here:
for your case it might be something like this:

const blocks = editor.BlockManager.getAll();
        blocks.map(block => {
            if(block.attributes.id === 'block-1'){
                block.attributes.category = {
                    label:"cat 1",
                    order:1
                }
            }
            else if(block.attributes.id === 'block-2'){
                block.attributes.category = {
                    label:"cat 2",
                    order:2
                }
            }
            else if (block.attributes.id === 'block-3'){
                block.attributes.category = {
                    label:"cat 3",
                    order:3
                }
            }
        })

cheers!

Thank you! I'll try it ASAP.
Have a good day.

All 3 comments

but I was able of adding it only on new categories created.

you can do this on all blocks by leveraging from getAll function. more on this here:
for your case it might be something like this:

const blocks = editor.BlockManager.getAll();
        blocks.map(block => {
            if(block.attributes.id === 'block-1'){
                block.attributes.category = {
                    label:"cat 1",
                    order:1
                }
            }
            else if(block.attributes.id === 'block-2'){
                block.attributes.category = {
                    label:"cat 2",
                    order:2
                }
            }
            else if (block.attributes.id === 'block-3'){
                block.attributes.category = {
                    label:"cat 3",
                    order:3
                }
            }
        })

cheers!

but I was able of adding it only on new categories created.

you can do this on all blocks by leveraging from getAll function. more on this here:
for your case it might be something like this:

const blocks = editor.BlockManager.getAll();
        blocks.map(block => {
            if(block.attributes.id === 'block-1'){
                block.attributes.category = {
                    label:"cat 1",
                    order:1
                }
            }
            else if(block.attributes.id === 'block-2'){
                block.attributes.category = {
                    label:"cat 2",
                    order:2
                }
            }
            else if (block.attributes.id === 'block-3'){
                block.attributes.category = {
                    label:"cat 3",
                    order:3
                }
            }
        })

cheers!

Thank you! I'll try it ASAP.
Have a good day.

Why am I getting an error "Uncaught TypeError: n is undefined" here?

In the post #780 it should be possible to change the order of blocks in the following way

const bm = editor.BlockManager;

["link", "map", "h-navbar", "countdown", "form", ...
].forEach(function (item) {
bm.remove( item );
});

const bl_text = bm.get('text').set({
label: 'Titel',
category: "My category",
});
const bl_textbasic = bm.get('text-basic').set({
label: 'Tekst',
category: "My category",
});
const bl_image = bm.get('image').set({
label: 'Afbeelding',
category: "My category",
});
const bl_video = bm.get('video').set({
label: 'Video',
category: "My category",
attributes: {class:"fab fa-youtube"},
});
const bl_quote = bm.get('quote').set({
label: 'Quote',
category: "My category",
});

bm.render([
bl_text, bl_textbasic, bl_image, bl_video, bl_quote,
]);

Please help what am I doing wrong?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ionic666 picture ionic666  路  3Comments

applibs picture applibs  路  3Comments

tribulant picture tribulant  路  3Comments

krunal039 picture krunal039  路  3Comments

nojacko picture nojacko  路  3Comments