Open a edit dialog in Event InitComplete
Open a edit dialog in Event InitComplete

After loading all data and displaying I want to open a certain row for edit. How can I do this?
The row has the id="dev" inside the table data, so i tried this way:
"initComplete": function(settings, json) {
$("#dev").addClass("selected");
$("#dev").click();
$(".buttons-selected").removeClass("disabled");
$(".buttons-selected").click();
}
This flags the correct row and enables the edit-button, but just opens a blank edit dialog without any content. How can I get this?
This discussion has been closed.
Answers
I think you would need to use the api and you would need the dt select extension as well.
Hi rf123,
thank you for your help... I tried this code but got an error:
ReferenceError: table is not defined
How do I have to initialize "table" here?
var table = $('#yourDataTable').DataTable( { ...
table
is the Datatables API. You maybe using a different name or haven't assigned the API to a variable. This doc shows how to access the API.Kevin
Found the solution by myself:
Very strage here: if it's done too fast, you'll get the empty editor dialog with error:
TypeError: b is undefine
Don't see enough of your code to be able to tell, but consider that JS is asynchronous and that lots of code get executed initializing a Data Table for example. Using the API events or promises is good practice - or simple timeouts can be helpful as well.
If you stick to using the API events you will hardly ever need timeouts or promises though.
You are better off using the
init
event as shown by rf1234. If, for some reason, it takes longer than 1 second to load your table you will see errors. You will want something like this:Kevin
Hi Kevin,
I tried it this way, but the error still remains:
Is this using Editor? If so, your line 25 should be using an Editor object for
edit()
.Are you able to link to your page or create a test case so we can take a look?
Colin
Hi Colin,
the website internal so i cannot provide a link to the page, but I can provider the content of the script-Tag. This is my "workaround" with setTimeout:
You have:
Try removing one of the
.on("init").
so it looks like this:Kevin
Ignore my previous comment, I've just learned something new - I didn't realise you could call
edit()
off ofrow()
- you learn something every day!Colin
Also in line 88 of the above you can assign the Datatables API to the variable table, like this:
var table = $('#aclAccess').DataTable({
.This will remove the
ReferenceError: table is not defined
error.Kevin
Hi Kevin,
I tried it this way, but the error still remains:
You've still got the double
init
- see Kevin's comment two back, he gave a code sample showing how to remove it.Colin
If you make the change suggested of removing the duplicated
.on("init")
in line 24 then please let us know what happens. Saying the error remains doesn't help us understand what is happening or not happening.Kevin