Skip to content

Commit 26a211e

Browse files
author
Steffen
committed
auto generated row_id option added
1 parent 52e0160 commit 26a211e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Command/GenerateDatatableCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
8080
throw new RuntimeException('The datatable class generator does not support entities with multiple primary keys.');
8181
}
8282

83+
$primaryKey = $metadata[0]->identifier;
84+
8385
if (0 == count($fields)) {
8486
$fields = $this->getFieldsFromMetadata($metadata[0]);
8587
}
8688

8789
$bundle = $this->getContainer()->get('kernel')->getBundle($bundle);
8890

8991
$generator = $this->getGenerator($bundle);
90-
$generator->generate($bundle, $entity, $fields, $ajaxUrl, $bootstrap);
92+
$generator->generate($bundle, $entity, $fields, $ajaxUrl, $bootstrap, $primaryKey[0]);
9193

9294
$output->writeln(
9395
sprintf(

Generator/DatatableGenerator.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ public function getClassPath()
7979
* @param array $fields The datatable fields
8080
* @param string $ajaxUrl The ajax url
8181
* @param boolean $bootstrap3 The bootstrap3 flag
82-
*
83-
* @throws RuntimeException
82+
* @param mixed $primaryKey
8483
*/
85-
public function generate(BundleInterface $bundle, $entity, array $fields, $ajaxUrl, $bootstrap3)
84+
public function generate(BundleInterface $bundle, $entity, array $fields, $ajaxUrl, $bootstrap3, $primaryKey)
8685
{
8786
$parts = explode("\\", $entity);
8887
$entityClass = array_pop($parts);
@@ -101,7 +100,6 @@ public function generate(BundleInterface $bundle, $entity, array $fields, $ajaxU
101100

102101
$this->ajaxUrl = $ajaxUrl? $ajaxUrl : $entityClassLowerCase . '_results';
103102

104-
105103
$this->renderFile('class.php.twig', $this->classPath, array(
106104
'namespace' => $bundle->getNamespace(),
107105
'entity_namespace' => implode('\\', $parts),
@@ -112,7 +110,8 @@ public function generate(BundleInterface $bundle, $entity, array $fields, $ajaxU
112110
'fields' => $fields,
113111
'ajax_url' => $this->ajaxUrl,
114112
'bootstrap3' => (boolean) $bootstrap3,
115-
'route_pref' => $entityClassLowerCase
113+
'route_pref' => $entityClassLowerCase,
114+
'primary_key' => $primaryKey
116115
));
117116
}
118117
}

Resources/views/Skeleton/class.php.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class {{ datatable_class }} extends AbstractDatatableView
9292
{% else -%}
9393
'use_integration_options' => false,
9494
{% endif -%}
95-
'force_dom' => false
95+
'force_dom' => false,
96+
'row_id' => '{{ primary_key }}'
9697
));
9798
9899
$this->columnBuilder

0 commit comments

Comments
 (0)