{% extends 'APYDataGridBundle::grid.html.twig' %} {% block grid_scripts_goto %} function {{ grid.hash }}_goto(url, data, type) { type = type || 'GET'; data = data || []; $.ajax({ url: url, data: data, type: type }).done(function( msg ) { $('#{{ grid.hash }}').parent().replaceWith(msg); }); return false } {% endblock grid_scripts_goto %} {% block grid_scripts_submit_form %} function {{ grid.hash }}_submitForm(event, form) { if (event.type != 'keypress' || event.which == 13) { var data = ''; $('.grid-filter-operator select, .grid-filter-input-query-from, .grid-filter-input-query-to, .grid-filter-select-query-from, .grid-filter-select-query-to', form).each(function () { if ($(this).is(':disabled') == false) { var name = $(this).attr('name'); var value = $(this).val(); if (value != null) { if ($(this).attr('multiple') == 'multiple') { for(var i= 0; i < value.length; i++) { data += '&' + name + '=' + value[i]; } } else { data += '&' + name + '=' + value; } } else { data += '&' + name + '='; } } }); {{ grid.hash }}_goto('{{ grid.routeUrl }}', data.substring(1), 'POST'); return false; } } {% endblock grid_scripts_submit_form %} {% block grid_scripts_ajax %} $(function () { // Order and pagerfanta links $('.pagination li.disabled a', '#{{ grid.hash }}').click(function (e) { return false; }); // Order and pagerfanta links $('a.order, nav a, a.searchOnClick, .pagination li:not(.disabled) a', '#{{ grid.hash }}').click(function () { {{ grid.hash }}_goto(this.href); return false; }); // Reset link $('#{{ grid.hash }} a.grid-reset').click(function () { {{ grid.hash }}_reset(); return false; }); // Mass actions submit $('#{{ grid.hash }} input.submit-massaction').click(function () { var selector = $('#{{ grid.hash }} .grid_massactions select'); {{ grid.hash }}_goto('{{ grid.routeUrl }}', selector.attr('name') + '=' + selector.val(), 'POST'); return false; }); // Grid_search submit (load only one time) $('#{{ grid.hash }}_search').one('submit', function (event) { {{ grid.hash }}_submitForm(event, this); return false; }); }); {% endblock grid_scripts_ajax %}