Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Fix custom DQL & render HTML #893

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Datatable/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ class Events
*/
protected $xhr;

/**
* Fired when responsive extension resizing table.
*
* @var null|array
*/
protected $responsiveResize;

//-------------------------------------------------
// Ctor.
//-------------------------------------------------
Expand Down Expand Up @@ -178,6 +185,7 @@ public function configureOptions(OptionsResolver $resolver)
'state_load_params' => null,
'state_save_params' => null,
'xhr' => null,
'responsive_resize' => null,
));

$resolver->setAllowedTypes('column_sizing', array('null', 'array'));
Expand All @@ -195,6 +203,7 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setAllowedTypes('state_load_params', array('null', 'array'));
$resolver->setAllowedTypes('state_save_params', array('null', 'array'));
$resolver->setAllowedTypes('xhr', array('null', 'array'));
$resolver->setAllowedTypes('responsive_resize', array('null', 'array'));

return $this;
}
Expand Down Expand Up @@ -622,4 +631,32 @@ public function setXhr($xhr)

return $this;
}

/**
* Get ResponsiveResize.
*
* @return array|null
*/
public function getResponsiveResize()
{
return $this->responsiveResize;
}

/**
* Set responsiveResize.
*
* @param array|null $responsiveResize
*
* @return $this
*/
public function setResponsiveResize($responsiveResize)
{
if (is_array($responsiveResize)) {
$this->validateArrayForTemplateAndOther($responsiveResize);
}

$this->responsiveResize = $responsiveResize;

return $this;
}
}
7 changes: 0 additions & 7 deletions Resources/views/datatable/datatable_html.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@
</tr>
{% endif %}
{% endif %}
<tr>
{% for column in sg_datatables_view.columnBuilder.columns %}
{% if column.sentInResponse %}
<th>{{ column.title }}</th>
{% endif %}
{% endfor %}
</tr>
</thead>
{% if true == individual_filtering %}
{% if 'foot' == sg_datatables_view.options.individualFilteringPosition or 'both' == sg_datatables_view.options.individualFilteringPosition%}
Expand Down
8 changes: 8 additions & 0 deletions Resources/views/datatable/events.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@
{% endif %}
.on('xhr.dt', {% include sg_datatables_view.events.xhr['template'] with vars %})
{% endif %}
{% if sg_datatables_view.events.responsiveResize is not same as(null) %}
{% if sg_datatables_view.events.responsiveResize['vars'] is defined %}
{% set vars = sg_datatables_view.events.responsiveResize['vars'] %}
{% else %}
{% set vars = {} %}
{% endif %}
.on('responsive-resize.dt', {% include sg_datatables_view.events.responsiveResize['template'] with vars %})
{% endif %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no newline at the end of file

38 changes: 19 additions & 19 deletions Resources/views/render/datetime.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,34 @@
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
#}
{%- set datetime_id_selector -%}
sg-datatables-{{ datatable_name }}-datetime-{{ row_id }}
{%- set datetime_id_selector -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary whitespace in front of this line

sg-datatables-{{ datatable_name }}-datetime-{{ row_id }}
{%- endset -%}

{%- set datetime_selector -%}
id="{{ datetime_id_selector }}"
id="{{ datetime_id_selector }}"
{%- endset -%}

{% if column_class_editable_selector is defined %}
<div {{ datetime_selector }} class="{{ column_class_editable_selector }}" data-pk="{{ pk }}" {% if path is not same as(null) %}data-path="{{ path }}"{% endif %}></div>
<span {{ datetime_selector }} class="{{ datetime_id_selector }} {{ column_class_editable_selector }}" data-pk="{{ pk }}" {% if path is not same as(null) %}data-path="{{ path }}"{% endif %}></span>
{% else %}
<div {{ datetime_selector }}>
{% if data is same as(null) and default_content is not same as(null) %}
{{ default_content }}
{% endif %}
</div>
<span {{ datetime_selector }} class="{{ datetime_id_selector }}">
{% if data is same as(null) and default_content is not same as(null) %}
{{ default_content }}
{% endif %}
</span>
{% endif %}

{% if data is not same as(null) %}
<script type="text/javascript">
$(function() {
moment.locale("{{ app.request.locale }}");
<script type="text/javascript">
$(function() {
moment.locale("{{ app.request.locale }}");

{% if timeago is same as(false) %}
$("#{{ datetime_id_selector }}").html(moment.unix({{ data|date('U') }}).format("{{ date_format }}"));
{% else %}
$("#{{ datetime_id_selector }}").html(moment.unix({{ data|date('U') }}).fromNow());
{% endif %}
});
</script>
{% if timeago is same as(false) %}
$(".{{ datetime_id_selector }}").html(moment.unix({{ data|date('U') }}).format("{{ date_format }}"));
{% else %}
$(".{{ datetime_id_selector }}").html(moment.unix({{ data|date('U') }}).fromNow());
{% endif %}
});
</script>
{% endif %}
7 changes: 6 additions & 1 deletion Response/DatatableQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ private function initColumnArrays()
// Order on alias column name
$this->addOrderColumn($column, null, $columnAlias);
// Fix subqueries alias duplication
$searchDql = preg_replace('/\{([\w]+)\}/', '$1_search', $dql);
// Another fix customDql to identify field select from base request and Subrequest
if (preg_match('/^SELECT/i', $dql)) {
$searchDql = preg_replace('/\{([\w]+)\}/', '$1_search', $dql); // original
} else {
$searchDql = preg_replace('/\{([\w]+)\}/', '$1', $dql);
}
$this->addSearchColumn($column, null, $searchDql);
} elseif (true === $this->accessor->getValue($column, 'selectColumn')) {
$parts = explode('.', $dql);
Expand Down