-
Notifications
You must be signed in to change notification settings - Fork 241
Icon does not display in action column #52
Comments
Try removing the renderif block. If your entity does not have a column called "visible" it won't render actions. |
Thanks for your quick answer. Any ideas ? |
Are you getting javascript or ajax error 500 in your console? By the way, the rel tooltip won't work unless you trigger the Bootstrap tooltip after ajax finishes loading. Also, in Bootstrap 3 it should be data-toggle="tooltip" instead of rel="tooltip" (Bootstrap 2). Mine looks like this: "actions" => array(
array(
"route" => "client_show",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-eye-open",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Show"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_ADMIN",
),
array(
"route" => "client_edit",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-edit",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Edit"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_ADMIN",
), If you are getting an error 500 from AJAX response saying the route does not exist, I guess you are getting issues with routing exposure. Make sure your controller action looks like this: /**
* Finds and displays a Client entity.
*
* @Route("/{id}", name="client_show", options={"expose"=true})
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
// ... Note the |
The first thing I've done was to check in Firebug if I did not have any 500 status code in Network or XHR, and I do not have. I've almost the same code as you, I've tried to add the expose option on my controller but with no effects. My code :
And my Controller :
So I don't know where might be the trouble ... |
Are you using at least v0.5.2 or master? 0.5.1 had some issues with this. <script src="/fdelapena/web/bundles/fosjsrouting/js/router.js"></script>
<script src="/fdelapena/web/app_dev.php/js/routing?callback=fos.Router.setData"></script> |
Hi, I am using the dev-master version.
Apparently everything might be fine, but icon still does not display |
Did you clear all cache and keeping I don't know why is failing then for you. Here is my configuration, just for reference: Here is my clientController.php: <?php
namespace Fdelapena\SomeBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Fdelapena\SomeBundle\Entity\Client;
use Fdelapena\SomeBundle\Form\ClientType;
/**
* Client controller.
*
* @Route("/panel/client")
*/
class ClientController extends Controller
{
/**
* Lists all Client entities.
*
* @Route("/", name="client")
* @Method("GET")
* @Template()
*
* @return array
*/
public function indexAction()
{
$clientDatatable = $this->get("sg_datatables.client");
$clientDatatable->buildDatatableView();
return array(
"datatable" => $clientDatatable,
);
}
/**
* Get all Client entities.
*
* @Route("/results", name="client_results")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function indexResultsAction()
{
/**
* @var \Sg\DatatablesBundle\Datatable\Data\DatatableData $datatable
*/
$datatable = $this->get("sg_datatables.datatable")->getDatatable($this->get("sg_datatables.client"));
return $datatable->getResponse();
}
/**
* @Route("/bulk/delete", name="client_bulk_delete")
* @Method("POST")
*
* @return Response
*/
public function bulkDeleteAction()
{
$request = $this->getRequest();
$isAjax = $request->isXmlHttpRequest();
if ($isAjax) {
$choices = $request->request->get("data");
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository("FdelapenaSomeBundle:Client");
foreach ($choices as $choice) {
$entity = $repository->findOneByUsername($choice["value"]);
$em->remove($entity);
}
$em->flush();
return new Response("This is ajax response.");
}
return new Response("This is not ajax.", 400);
}
/**
* @Route("/bulk/disable", name="client_bulk_disable")
* @Method("POST")
*
* @return Response
*/
public function bulkDisableAction()
{
$request = $this->getRequest();
$isAjax = $request->isXmlHttpRequest();
if ($isAjax) {
$choices = $request->request->get("data");
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository("FdelapenaSomeBundle:Client");
foreach ($choices as $choice) {
var_dump($choice["value"]);
$entity = $repository->findOneByUsername($choice["value"]);
$entity->setEnabled(false);
$em->persist($entity);
}
$em->flush();
return new Response("This is ajax response.");
}
return new Response("This is not ajax.", 400);
}
/**
* @Route("/bulk/enable", name="client_bulk_enable")
* @Method("POST")
*
* @return Response
*/
public function bulkEnableAction()
{
$request = $this->getRequest();
$isAjax = $request->isXmlHttpRequest();
if ($isAjax) {
$choices = $request->request->get("data");
$em = $this->getDoctrine()->getManager();
$repository = $em->getRepository("FdelapenaSomeBundle:Client");
foreach ($choices as $choice) {
$entity = $repository->findOneByUsername($choice["value"]);
$entity->setEnabled(true);
$em->persist($entity);
}
$em->flush();
return new Response("This is ajax response.");
}
return new Response("This is not ajax.", 400);
}
/**
* Creates a new Client entity.
*
* @Route("/", name="client_create")
* @Method("POST")
* @Template("FdelapenaSomeBundle:Client:new.html.twig")
*/
public function createAction(Request $request)
{
$entity = new Client();
$form = $this->createCreateForm($entity);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client_show', array('id' => $entity->getId())));
}
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Creates a form to create a Client entity.
*
* @param Client $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createCreateForm(Client $entity)
{
$form = $this->createForm(new ClientType(), $entity, array(
'action' => $this->generateUrl('client_create'),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Create'));
$form->get('enabled')->setData(true);
return $form;
}
/**
* Displays a form to create a new Client entity.
*
* @Route("/new", name="client_new")
* @Method("GET")
* @Template()
*/
public function newAction()
{
$entity = new Client();
$form = $this->createCreateForm($entity);
return array(
'entity' => $entity,
'form' => $form->createView(),
);
}
/**
* Finds and displays a Client entity.
*
* @Route("/{id}", name="client_show", options={"expose"=true})
* @Method("GET")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'delete_form' => $deleteForm->createView(),
);
}
/**
* Displays a form to edit an existing Client entity.
*
* @Route("/{id}/edit", name="client_edit", options={"expose"=true})
* @Method("GET")
* @Template()
*/
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$editForm = $this->createEditForm($entity);
$deleteForm = $this->createDeleteForm($id);
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Creates a form to edit a Client entity.
*
* @param Client $entity The entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEditForm(Client $entity)
{
$form = $this->createForm(new ClientType(), $entity, array(
'action' => $this->generateUrl('client_update', array('id' => $entity->getId())),
'method' => 'POST',
));
$form->add('submit', 'submit', array('label' => 'Update'));
$form->remove('plainPassword');
return $form;
}
/**
* Edits an existing Client entity.
*
* @Route("/{id}", name="client_update")
* @Method({"POST"})
* @Template("FdelapenaSomeBundle:Client:edit.html.twig")
*/
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$deleteForm = $this->createDeleteForm($id);
$editForm = $this->createEditForm($entity);
$editForm->handleRequest($request);
if ($editForm->isValid()) {
$em->flush();
return $this->redirect($this->generateUrl('client_show', array('id' => $id)));
}
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
/**
* Deletes a Client entity.
*
* @Route("/{id}/delete", name="client_delete", options={"expose"=true})
* @Method({"GET", "POST"})
*/
public function deleteAction(Request $request, $id)
{
$form = $this->createDeleteForm($id);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$em->remove($entity);
$em->flush();
return $this->redirect($this->generateUrl('client'));
}
/**
* Disables a Client entity.
*
* @Route("/{id}/disable", name="client_disable", options={"expose"=true})
* @Method({"GET", "POST"})
*/
public function disableAction(Request $request, $id)
{
$form = $this->createDisableForm($id);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$entity->setEnabled(false);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client'));
}
/**
* Enables a Client entity.
*
* @Route("/{id}/enable", name="client_enable", options={"expose"=true})
* @Method({"GET", "POST"})
*/
public function enableAction(Request $request, $id)
{
$form = $this->createEnableForm($id);
$form->handleRequest($request);
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('FdelapenaSomeBundle:Client')->find($id);
if (!$entity) {
throw $this->createNotFoundException('Unable to find Client entity.');
}
$entity->setEnabled(true);
$em->persist($entity);
$em->flush();
return $this->redirect($this->generateUrl('client'));
}
/**
* Creates a form to enable a Client entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createEnableForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('client_enable', array('id' => $id)))
->setMethod('POST')
->add('submit', 'submit', array('label' => 'Enable'))
->getForm()
;
}
/**
* Creates a form to disable a Client entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDisableForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('client_disable', array('id' => $id)))
->setMethod('POST')
->add('submit', 'submit', array('label' => 'Disable'))
->getForm()
;
}
/**
* Creates a form to delete a Client entity by id.
*
* @param mixed $id The entity id
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm($id)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('client_delete', array('id' => $id)))
->setMethod('POST')
->add('submit', 'submit', array('label' => 'Delete'))
->getForm()
;
}
} My services.yml: services:
sg_datatables.client:
class: Fdelapena\SomeBundle\Datatables\ClientDatatable
tags:
- { name: sg.datatable.view } My routing.yml: client:
resource: "@FdelapenaSomeBundle/Controller/ClientController.php"
type: annotation My config.yml: assetic:
assets:
data_tables_css:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/3/dataTables.bootstrap.css
output: css/datatables.css
filter: [cssrewrite]
data_tables_js:
inputs:
- %kernel.root_dir%/../vendor/datatables/datatables/media/js/jquery.dataTables.js
- %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/3/dataTables.bootstrap.js
output: js/datatables.js
moment_js:
inputs:
- '%kernel.root_dir%/../vendor/moment/moment/moment.js'
output: js/moment.js
moment_locale:
inputs:
- '%kernel.root_dir%/../vendor/moment/moment/lang/%locale%.js'
output: js/moment.locale.js
data_tables_jquery_css:
input: %kernel.root_dir%/../vendor/datatables/datatables/media/css/jquery.dataTables.css
output: css/jquery.dataTables.css
filter: ['cssrewrite']
data_tables_bootstrap_css:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/3/dataTables.bootstrap.css
output: css/dataTables.bootstrap.css
filter: ['cssrewrite']
data_tables_responsive_css:
input: %kernel.root_dir%/../vendor/datatables/responsive/css/dataTables.responsive.css
output: css/dataTables.responsive.css
data_tables_responsive_js:
input: %kernel.root_dir%/../vendor/datatables/responsive/js/dataTables.responsive.js
output: js/dataTables.responsive.js
data_tables_bootstrap_js:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/3/dataTables.bootstrap.js
output: js/datatables.js
data_tables_img_sort_both:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/images/sort_both.png
output: images/sort_both.png
data_tables_img_sort_asc:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/images/sort_asc.png
output: images/sort_asc.png
data_tables_img_sort_desc:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/images/sort_desc.png
output: images/sort_desc.png
data_tables_img_sort_asc_disabled:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/images/sort_asc_disabled.png
output: images/sort_asc_disabled.png
data_tables_img_sort_desc_disabled:
input: %kernel.root_dir%/../vendor/datatables/plugins/integration/bootstrap/images/sort_desc_disabled.png
output: images/sort_desc_disabled.png My custom CSS: table.dataTable.dtr-inline.collapsed tbody td.dataTables_empty:first-child:before,
table.dataTable.dtr-inline.collapsed tbody th.dataTables_empty:first-child:before {
display: none;
}
td.action-cell {
padding: 0.125em 0 0 !important;
text-align: center;
}
td.multiselect-checkbox-cell {
padding-left: 18px !important;
padding-right: 18px !important;
}
td .glyphicon-ok:before {
color: green;
}
td .glyphicon-remove:before {
color: red;
} My custom JavaScript to add better experience: $(document).ready(function() {
// Make popover position responsive
$('[data-toggle=popover]').popover({
container: 'body',
trigger: 'focus',
placement: function() { return $(window).width() < 975 ? 'top' : 'right'; }
});
// Add datatables responsiveness (requires datatables responsive plugin)
$('#client_datatable').addClass('dt-responsive');
}
$(document).on('ajaxComplete', function() {
// Add bootstrap 3 style to bulk actions dropdown and submit
$('[name="bulk_action_routes[select]"]').addClass('form-control');
$('#multiselect_submit').addClass('btn btn-default');
// Enable tooltip functionality
$('[data-toggle=tooltip]').tooltip({container: 'body'});
}); My index.html.twig: {% extends "FdelapenaSomeBundle::layout.html.twig" %}
{% block title %}{% trans %}Clients{% endtrans %}{% endblock %}
{% block content_header '' %}
{% block content %}
<h1>{% trans %}Clients{% endtrans %}</h1>
<p class="btn-group">
<a href="{{ path('client_new') }}" class="btn btn-success">
<span class="glyphicon glyphicon glyphicon-plus"></span>
{% trans %}New client{% endtrans %}
</a>
</p>
<p>
{% trans %}Client list:{% endtrans %}
</p>
{% block content_content %}
{{ datatable_render(datatable) }}
{% endblock %}
{% endblock %} My ClientDatatable.php: <?php
namespace Fdelapena\SomeBundle\Datatables;
use Sg\DatatablesBundle\Datatable\View\AbstractDatatableView;
/**
* Class ClientDatatable
*
* @package Fdelapena\SomeBundle\Datatables
*/
class ClientDatatable extends AbstractDatatableView
{
/**
* {@inheritdoc}
*/
public function buildDatatableView()
{
$this->getFeatures()
->setServerSide(true)
->setProcessing(true);
$this->getAjax()->setUrl($this->getRouter()->generate("client_results"));
$this->getMultiselect()
->setEnabled(true)
->setPosition("last")
->setWidth("0.875em")
->setClassName("multiselect-checkbox-cell")
->addAction($this->getTranslator()->trans("Disable selected clients"), "client_bulk_disable")
->addAction($this->getTranslator()->trans("Enable selected clients"), "client_bulk_enable")
->addAction($this->getTranslator()->trans("Delete selected clients"), "client_bulk_delete");
$this->setStyle(self::BOOTSTRAP_3_STYLE);
$this->getColumnBuilder()
->add('id', 'column', array('title' => $this->getTranslator()->trans('Id'),))
->add('username', 'column', array('title' => $this->getTranslator()->trans('Username'),))
->add('email', 'column', array('title' => $this->getTranslator()->trans('Email'),))
->add('firstName', 'column', array('title' => $this->getTranslator()->trans('First name'),))
->add('lastName', 'column', array('title' => $this->getTranslator()->trans('Last name'),))
->add('enabled', 'boolean', array(
"title" => $this->getTranslator()->trans("Enabled"),
"true_icon" => "glyphicon glyphicon-ok",
"false_icon" => "glyphicon glyphicon-remove",
"true_label" => $this->getTranslator()->trans("Yes"),
"false_label" => $this->getTranslator()->trans("No"),
))
->add(null, "action", array(
"title" => $this->getTranslator()->trans("Actions"),
"start" => '<span class="btn-group">',
"end" => '</span>',
"class" => "action-cell",
"width" => "11em",
"actions" => array(
array(
"route" => "client_show",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-eye-open",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Show"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_ADMIN",
),
array(
"route" => "client_edit",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-edit",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Edit"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_ADMIN",
),
array(
"route" => "client_disable",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-ban-circle",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Disable"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_USER",
"renderif" => array("enabled"),
),
array(
"route" => "client_enable",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-ok-circle",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Enable"),
"class" => "btn btn-default",
"role" => "button"
),
"role" => "ROLE_USER",
"renderif" => array("enabled) == false; var dummy = function(){}; dummy("),
),
array(
"route" => "client_delete",
"route_parameters" => array(
"id" => "id"
),
"icon" => "glyphicon glyphicon-trash",
"attributes" => array(
"data-toggle" => "tooltip",
"title" => $this->getTranslator()->trans("Delete"),
"class" => "btn btn-default",
"role" => "button"
),
"confirm" => true,
"confirm_message" => $this->getTranslator()->trans("This operation will erase the client, all its groups and all their contacts"),
"role" => "ROLE_ADMIN",
)
)
))
;
}
/**
* {@inheritdoc}
*/
public function getEntity()
{
return "Fdelapena\SomeBundle\Entity\Client";
}
/**
* {@inheritdoc}
*/
public function getName()
{
return "client_datatable";
}
} My layout.html.twig head: <head>
{% block head %}
<meta http-equiv="Content-Type" content="text/html; charset={{ _charset }}"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}" />
<link rel="stylesheet" href="{{ asset('css/bootstrap.css') }}" />
{% block stylesheets %}
{% stylesheets
'@data_tables_css'
'@data_tables_responsive_css'
'@FdelapenaSomeBundle/Resources/public/css/site.css'
output='css/sit.css' filter='cssrewrite'
%}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
{% block javascripts %}
<script src="{{ asset('js/jquery.js') }}"></script>
<script src="{{ asset('js/bootstrap.js') }}"></script>
<script src="{{ asset('bundles/fosjsrouting/js/router.js') }}"></script>
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
<script type="text/javascript" src="/support/js/compiled/widget.js"></script>
{% javascripts
'@moment_js'
'@data_tables_js'
'@data_tables_responsive_js'
'@data_tables_bootstrap_js'
'@FdelapenaSomeBundle/Resources/public/js/site.js'
output='js/site.js'
%}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% if app.request.locale != 'en' %}
<script src="{{ asset('js/moment.locale.js') }}"></script>
{% endif %}
{% endblock %}
<title>{% block title %}{% endblock %} - {% trans %}Some site{% endtrans %}</title>
{% endblock %}
</head> |
@fdelapena thanks for your example. You're right. This problem should be fixed with version 0.5.2 |
Thanks a lot for your example. Regards, |
TypeError: document.body is null |
Hello,
I'm trying for few times to display the "glyphicon glyphicon-edit" with the same way of your example but in vain.
Indeed, the icon does not want to display and the column still stay empty without any button inside.
There is my code :
Do you know where might be my mistake ?
Thanks by advance,
The text was updated successfully, but these errors were encountered: