Error when I tried to add rows to a table
I forget put what version I am using grapesjs - 0.13.5 <link rel="stylesheet" href="Config/grapesjs-dev/dist/css/grapes.min.css"> <link rel="stylesheet" href="Config/grapesjs-preset-webpage-master/dist/grapesjs-preset-webpage.min.css"/> <script src="Config/grapesjs-dev/dist/grapes.min.js"></script> <script src="Config...
Read full answer below ↓Question
Hi guys I'm starting to use Grapesjs and I have a problem, I am trying to add 3 new commands to create tables, add rows and cells, the table works fine but when I add a row into the table I get this error: "Invalid target position: Target collection not found, Target is not droppable, accepts [undefined], Component not draggable, acceptable by [undefined] ", could someone help me, this is my code : I appreciate it the help
`<script type="text/javascript">
var editor = grapesjs.init({
height: '100%',
showOffsets: 1,
noticeOnUnload: 0,
storageManager: {autoload: 0},
container: '#gjs',
fromElement: true,
plugins: ['gjs-preset-webpage'],
pluginsOpts: {
'gjs-preset-webpage': {}
}
});
var bm = editor.BlockManager;
var comps = editor.DomComponents;
var defaultType = comps.getType('default');
var defaultModel = defaultType.model;
var defaultView = defaultType.view;
bm.add('table', {
label: 'Table',
content: '<table><thead><th></th></thead><tbody><tr><td>Test</td></tr ></tbody></table>',
attributes: {
'data-type': 'table',
},
});
bm.add('tr', {
label: 'Row',
content: '<tr><td>Test</td></tr>',
attributes: {
'data-type': 'tr',
},
});
bm.add('td', {
label: 'Cell',
content: '<td>Test</td>',
attributes: {
'data-type': 'td',
},
});
comps.addType('table', {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
'custom-name': 'Table',
draggable: true,
droppable: true,
accepted: true,
highlightable: true,
stylable: [
' height', 'font-style', 'font-size', 'font-weight', 'font-family', 'color',
'width'
],
style: {
'width': '100%',
'font-size': '14px'
},
}),
},
{
isComponent: function(el) {
if(el.tagName === 'TABLE'){
return {type: 'table'};
}
},
}),
view: defaultType.view,
});
comps.addType('tr', {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
'custom-name': 'Row',
draggable: true,
droppable: true,
highlightable: true,
accepted: true,
}),
},
{
isComponent: function(el) {
if(el.tagName === 'TR'){
return {type: 'tr'};
}
},
}),
view: defaultType.view,
});
comps.addType('td', {
model: defaultModel.extend({
defaults: Object.assign({}, defaultModel.prototype.defaults, {
'custom-name': 'Td',
draggable: true,
droppable: true,
highlightable: true,
accepted: true,
}),
},
{
isComponent: function(el) {
if(el.tagName == 'TD'){
return {type: 'td'};
}
},
}),
view: defaultType.view,
});
</script>`Answers (3)
I forget put what version I am using grapesjs - 0.13.5 <link rel="stylesheet" href="Config/grapesjs-dev/dist/css/grapes.min.css"> <link rel="stylesheet" href="Config/grapesjs-preset-webpage-master/dist/grapesjs-preset-webpage.min.css"/> <script src="Config/grapesjs-dev/dist/grapes.min.js"></script> <script src="Config/grapesjs-preset-webpage-master/dist/grapesjs-preset-webpage.min.js"></script>
@davidherlopgt Have you tried to use built-in table components instead of extending them? BTW create a live demo please
Hi artf thanks for your answer, I tried to use the table component and I can add the Table with one row and one cell in the header and the body, maybe the disadvantage is that if I change the color of the row to the header the body is changed too, so I have to remove the class from the body row so that it is not affected I add the live demo like you ask grapesjslivedemo.zip
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1661
I've created html table and cannot drag new elements to table cells
Hello. if I create html table with next block of code, everything works, I'm able to drop a Quote, for example, to any cell: But next code...
Issue #1611
Script tag create JSON error
Hi. I'm creating blocks in Grapesjs and I need to use JS on them for hover effect and more.. Everything works fine for the creation, store,...
Issue #1407
[QUESTIONS] EXTRA TBODY ADDED EVERY TIME I SAVED THE HTML DATA.
Hi @artf, I had an issue when I have tables in the editor and I add new rows then if my table is saved when is loaded again an extra tbody...
Issue #511
Cannot edit the content after update it via block manager API
Hello @artf sorry for my last issue, I must create a new issue, my problem is got error like this EDIT : sorry i just fixed my last issue w...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Related tutorials
In-depth guides on the same topic.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.