Problem with select API
Problem with select API
Link to test case: http://live.datatables.net/bugefufi/1/edit?html,css,js,console,output, it doesn't work beacuase it requires php, but is for showing my complete code
Debugger code (debug.datatables.net): osezel
Error messages shown: no error message
Description of problem:
I send data to my php page with this type of array :
$colonne = array(
array(
'db' => 'IDAzienda',
'dt' => "IDAzienda",
'classname' => 'vertical-middle dc-center',
'orderable' => 'false',
'type' => 'button_plus',
'icon' => 'icon-plus',
'class' => 'btn btn-mini bnn btn-yellow'
),
array(
'db' => '',
'dt' => '',
'orderable' => 'false',
'classname' => 'vertical-middle dc-center',
'type' => 'checkbox'
), // and so on...
i send the array to sspclass
the json response is correct
as you can see in render
i cycle the php array and handle each type case of the column i need
In the fnCreatedRow
i create a function with onclick event :
const apririga = (tipo) => function(){
where i use fnOpen
to open the row i clicked on and write a new table:
var oTable = $('#scadenziario').dataTable();
// 'open' an information row when parent row is clicked
if (oTable.fnIsOpen($('#' + churchid).get(0)) ) {
oTable.fnClose($('#' + churchid).get(0)); // churchinfo div remains in DOM, saving us from future AJAX calls
} else {
oTable.fnOpen( $('#' + churchid).get(0), '<table id="riga_scadenziario_' + churchid + '" class="table table-bordered hover dataTable dtr-inline"> <thead> <th>Num.</th><th></th><th>Sel.</th><th>Attività</th><th>Tipo Documento</th><th>N° Documento</th><th>Data Documento</th><th>Data Scadenza</th><th>Originario</th><th>Residuo</th><th>N° Mail</th><th>N° Contatti</th><th>Stato 1</th><th>Stato 2</th><th>Anticipo</th><th>Spedire A</th><th>P.O.</th><th>Cod. Banca</th><th>Lista Email</th><th>Desc. 1</th><th>Desc. 2</th> </thead><tfoot><th colspan="8">Totale Selezionato</th><th></th><th></th><th colspan="11"></th></tfoot> </table>', "class-detail-row" );
}
after this i initialize the table created with datatable...this work pretty well, but when i clicked on the checkbox i need to select all of the rows of the second table
if i
console.log(rigaTabella.row(0).data());
it returns undefined (rigaTabella is the table created), you can see all of this in the code above
I think I made myself clear, tell me if you not understand.
I don't understand why it returns undefined, i have tried this to see if my table exist:
$.fn.dataTable.tables();
Replies
Your test case console is showing 48 errors.
i know, is because it needs php to go
Thats a lot of code to simply look at to try and debug the problem. Is it possible for to build a test case with example data (removing the PHP) so we can help debug? See this Javascript sourced data example.
Normally the
$.fn.dataTable.isDataTable()
is used to see if the table exists.Probably a scoping problem which is causing the
rigaTabella
to not be available. You can get an instance of the Datatable API with something like this:Where
myTableId
is the id of the table you want to use.Kevin
Hi kevin, thanks for your response
This is the new link http://live.datatables.net/bugefufi/2/edit?html,js,console,output, unfortunately i cant' show data for customer privacy
I put this:
and returned undefined
Since the actual data is not causing the problem we expect fake data.
You are getting this error in the browser's console:
Its due to having too many columns in your footer. I fixed that by chainging your last colspan to
7
.Datatables expects the data to be contained in an array so I changed your data variable to this:
Here is the updated test case:
http://live.datatables.net/wocamowa/1/edit
What are the steps to show the problem you are having.
Are you trying to create child detail rows as shown in this example?
Kevin
Thanks Kevin,
yes i am trying to create child detail rows, and with
fnCreatedRow
work pretty well, the row opens correctly and show data correctlyThe row opens after clicking one of these element:
Apririga is the function that create the new datatable
The problem is for selecting row...when i click on checkbox1[1] i need to select all of the rows of the table created, and i tried doing this:
rigaTabella.rows().select()
, but nothing happenedin the example you can see all of these function...maybe i call the api in the wrong place? i don't know
I clicked on the
A
in theRagione Sociale
column and an empty child row is opened. Is this correct?Please provide the steps of what to click. Just showing code snippets of what to click doesn't help us.
I'm not sure what this is in the test case.
Kevin
In the test case is correct because there aren't data for the second table
This is what happened when i click on the checkbox (checkbox1[1] in test case), you see empty for customer privacy,but i have to select all the row of second table
As you can see from the screenshot the table is created correctly
You and I must be looking at two different things. This is what I see in the test case:
Do you have an updated link for the screenshot you posted?
Kevin
The screenshot i posted is from my actual result, is not the same as the test case, but i posted the test case only for show you the complete code.
I can't replicate the result i have on test case
This is the point where i'm stuck:
We need to see the test case reproducing the problem you want help with. Otherwise, we could be talking cross-purposes.
Colin
This is new test case: http://live.datatables.net/wocamowa/2/edit?html,js,console,output..i don't understand why it works
I think the problem is that the data are loaded throught ajax, is there a way to open the row only on ajax success response?
Or a way to select all after data are loaded
Are you fetching the child row data via Ajax?
You can use the
initComplete
function to process the table after it has initialized.Kevin
I resolve the problem doing this :
But now i have another problem.. how can i sum data of a column of each row selected?
Are you using something like this example to sum the column? If so you can use
selector-modifier
of{selected:true}
. See the selected example in the docs.Kevin
I am referring to the second table created.
I have tried this :
I put that inside the function that creates the second table, but it doesn't return the selected column value...
Is there a way to get data of the second table outside the first one?
What is returned?
You code snippet works here:
http://live.datatables.net/kozamexe/1/edit
I only changed the column selector from
8
to0
for the test case.Can you update your test case to show the issue?
Kevin
Here is the new link: http://live.datatables.net/wocamowa/2/edit?html,js,console,output
i need the value of that column and a way to sum each value selected
You can use the sum() plugin to get the sum of a Datatabes dataset. For example:
http://live.datatables.net/cebukube/1/edit
Kevin
I get this error : rigaTabella.cells(...).data(...).sum is not a function
Did you load the plugin as described in the instructions?
Kevin
Oh sorry, i didn't see the link to include
Now im trying to sum the values of each row every time i select one, doing this:
After i need to know, if exist a way to get the row selected of the table created from outside the "general" table
Use the same technique. You may need to get an instance of the child table API as discussed here.
Kevin
I can't get the instace of the table created because i don't know the id of the table, because is dynamic
Maybe i can save the id into a hidden element
I don't know how to open all row : http://live.datatables.net/cebukube/2/edit?html,js,console,output, and why there isn't the th checkbox?
Any suggestions?
You can loop through all the rows with
rows().every()
and open them in the loop.The select extension doesn't add a checkbox in the
th
. You will need to add this manually or you can use the Gyrocode Checkboxes plugin which uses the select extension and adds a select all checkbox in the header.Kevin