Is there a way to put a dynamic message in the datatables editor?
Is there a way to put a dynamic message in the datatables editor?
Stacey1134
Posts: 112Questions: 20Answers: 0
The following pieces : field().message() field().fieldInfo() field().labelInfo() only accept string types. Is there something like fields.def which accepts a function?
$(document).ready(function() {
editor1 = new $.fn.dataTable.Editor( {
ajax: "ajaxCorrespondence.php",
table: "#correspondenceTable",
display: 'bootstrap',
fields: [ {
label: "Contact ID:",
name: "cr_id",
def: function () {
var gotID = $('#myClipboard').attr('data-crid');
return gotID;
},
message: function () {
var gotName = $('#myClipboard').attr('data-fname');
return gotName;
},
}, {
message won't work, and nothing else. I need add dynamic information that the user needs. I am actually combining variables when creating this info from elsewhere in the web app. Thanks.
This question has an accepted answers - jump to answer
Answers
I haven't used these APIs but it looks like
field().fieldInfo()
,field().labelInfo()
andfield().message()
support functions. The corresponding options for these, like in your code snippet only takes a string. It looks like you can useopen
event with the API's to dynamically set the values.Kevin
Thanks, in theory it could work. But I cant even get an the open event to work as standard. I copied it directly from here : https://editor.datatables.net/reference/api/open()
even in its most basic form won't activate, I am using the buton function , and these have no names I could find no id or names so I cannot catch the event.
I tried this:
even inside the one event handler that I can kick off
As well as every other variation I could try. I had tried before that's why I tried to go back to fields. But tried again after your post. Still no luck.
Here is an example:
https://live.datatables.net/guwafemu/367/edit
Using the standard editor Create and Edit buttons or the custom button,
newRecord
, is working. If this doesn't help then please update the test case to show what you are tying to do so we can help debug.Kevin
Oh my goodness. Somehow the message got crossed. I am not trying to create new buttons, I am trying to use the system as designed. There is not test case because there isn't a bug.
Thanks for trying, but this does not at all answer the question I posed, and unfortunately the solution posted here https://live.datatables.net/guwafemu/367/edit, require creating my own buttons. I am actually trying to use editor. I can easily make a bootstrap modal with my own buttons and text inside the modal. I am asking how to do it within the Editor framework.
Thanks anyway.
Scratch that, Thanks @kthorngren I totally missed this part in your example:
Well, a little different after I was done, but this work great. Thanks!
The example shows two options. One using the Editor's buttons and the other using a button with the id of
newRecord
. I assumed you wanted the second option based on this code snippet:I thought your questions where how to dynamically set field().message() field().fieldInfo() field().labelInfo() values. This is demonstrated in the example with this code:
Its likely I misunderstand your questions. If this doesn't help then my suggestions is to update the example with your solution. This way we can see exactly what you are trying to do to offer suggestions.
Kevin
Looks like we cross posted
Kevin