Editor post submit breaking columns created cell
Editor post submit breaking columns created cell
Jack7
Posts: 5Questions: 1Answers: 0
I'm using editor with bubble editing and everything works as it should. Post submit the row gets update correctly except cells that are populated with createdCell for example"
"createdCell": function (td, cellData, rowData, row, col) {
$(td).html(`<a href="javascript:void(0);" class="OpenPartialModal" data-target="#AddOrdEditSiteInventoryModal" data-url="${buttonPrefix}${rowData.id}">Edit</a>`);
}
Post update it sets that cell to display : [object Object]
Any idea what I'm doing wrong ?
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
Kevin
This question has an accepted answers - jump to answer
Answers
Its hard to say what the problem might be without seeing the issue.
columns.createdCell
only executes only once for each cell as it is created. It does't run again if that cell is updated. Sounds like the issue happens when trying to update the cell.Looks like that cell is a link - are you bubble editing that cell?
Do you want to bubble edit that cell?
Start by posting your full Editor and Datatables init code. Use the browser's network inspector to get the sent payload parameters and the response. Post both here - please use Markdown code formatting with the triple back ticks.
Better is a link to your page or test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
I'm so sorry for only replying now, things just ran away from me. Here is my code. I can add the other info if you still think its necessary after viewing a stripped down version of my code, I just left out some of the columns so ignore the target counts.
I bubble edit 4 columns only :
- priceAmended
- discountAmended
- additionalDiscount
- addOnCharge
Post submit everything updates perfectly, the cells with links are the ones that break and display (target 2, target 18, target 19) :
[object Object]
I think I understand now after seeing your code. I believe the problem is with using
columns.data
asnull
which assigns the full row of data to that cell.columns.createdCell
executes just once when the cell is initially inserted into the document. I believe that when the row is updated via the Editor the data in the columns withcolumns.data
set tonull
are also updated. Thus the[object Object]
display.I think you have two options:
-1. Use
columns.render
instead ofcolumns.createdCell
to display the links, for example:-2. Set the
columns.data
to an unused key name. Using this I think you will also need to usecolumns.defaultContent
. You can set the defaultContent to the link string or, in the case of a conditional, set it to an empty string and let thecolumns.createdCell
set the value. Keep in mind if thecellData.compliant
value changescolumns.createdCell
won;'t run again to update the cell.I would go with option 1 as it will keep the cells updated in case of changes.
Kevin
Thank you so much, option 1 worked exactly as you said it would.