Hi Nino,
Here is an minimal example of a view that displays a first datatable.
When a row is double-clicked, a modal dialog is shown with an embeded second datable with rows matching the datatable's row that has been double-clicked.
<!-- First datatable -->
<div id="first_datatable" class="zdk-datatable" title="First"
data-zdk-action="examplectrl:datafirst"
data-zdk-columns='[{"field":"first_id", "headerText": "First ID"},
{"field":"label", "headerText": "Label"}]'>
</div>
<!-- Modal dialog with second datatable -->
<div id="my_modal" class="zdk-modal" data-zdk-width="360px" title="Second datatable in a modal">
<div id="second_datatable" class="zdk-datatable" title="Second"
data-zdk-action="examplectrl:datasecond"
data-zdk-columns='[{"field":"first_id", "headerText": "First ID"},
{"field":"second_id", "headerText": "Second ID"},
{"field":"label", "headerText": "Label"}]'>
</div>
</div>
<script>
$('#first_datatable').on('zdkdatatablerowdblclicked', function(datatableObject, rowData) {
if ($('#second_datatable').hasClass('pui-datatable')) {
// The datatable has been previously instanciated
$('#second_datatable').zdkdatatable('filterRows', rowData.first_id);
} else {
// The datatable is not yet instanciated
$('#second_datatable').zdkdatatable({filterCriteria: rowData.first_id});
}
$('#my_modal').zdkmodal('show');
});
</script>
And the PHP code of the controller actions called by the two datatables :
<?php
namespace controller;
class ExampleCtrl extends \AppController {
static protected function action_datafirst() {
$response = new \Response();
$response->rows = [
['first_id' => 1, 'label' => 'One'],
['first_id' => 2, 'label' => 'Two'],
['first_id' => 3, 'label' => 'Three']
];
$response->success = true;
return $response;
}
static protected function action_datasecond() {
$request = new \Request();
$index = $request->search_criteria;
$allRows = [
1 => ['A', 'B', 'C'],
2 => ['D', 'E', 'F'],
3 => ['G', 'H', 'I']
];
$rows = [];
if (key_exists($index, $allRows)) {
foreach ($allRows[$index] as $key => $value) {
$rows[] = ['first_id' => $index, 'second_id' => $key + 1, 'label' => $value];
}
}
$response = new \Response();
$response->rows = $rows;
$response->success = true;
return $response;
}
}
Hoping you'll enjoy,
Pascal