Forums › Forums › OroCRM › OroCRM – How do I? Questions › Show/Hide icon in datagrid
This topic contains 9 replies, has 4 voices, and was last updated by prganvani 7 years, 1 month ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- February 3, 2016 at 4:17 am #28735
I have defined a datagrid for activity items. The activity can have the status open or closed. If the activity status is open than 2 icons (view, edit) should be shown, but if the status is closed than only the view icon should be shown. Closed activity can not be edited.
How can I implement this requirement?
pseudo code:
YAML12345678910actions:update:type: navigateicon: editlink: update_linkshow: record.get('itemstatus') == 1view:type: navigateicon: eye-openlink: view_linkThanks for helping
- CreatorTopic
- AuthorReplies
- February 4, 2016 at 2:47 am #28736
Hello, mike_m.
You have to use action configuration (or action permission provider) – this way you can enable/disable actions on a row level. See this example and this code.
February 4, 2016 at 7:11 am #28737Thanks for helping me out. It works perfectly.
July 19, 2016 at 12:58 am #28738Hi @Yevhen Shyshkin,
I use this in a project.
It works fine for one action but I use the same logic for another and it doesn’t works. I have a weird twig runtime error “type must be defined” instead… Type of what ? The action, I thought it was defined…YAML1234567891011121314151617181920212223242526272829303132333435363738#actions.ymlparameters:sinabs_monitoring.extension.action.type.custom.class: Sinabs\MonitoringBundle\Extension\Action\Actions\CustomActionservices:sinabs_monitoring.extension.action.type.custom:class: %sinabs_monitoring.extension.action.type.custom.class%scope: prototypetags:- { name: oro_datagrid.extension.action.type, type: custom }#datagrid.ymlactivate_link:type: urlroute: monitoring_api_activate_monitorparams:- idactivate:type: customacl_resource: monitoring.monitor_updatelabel: activate_monitoricon: okconfirmation: truelink: activate_linkdeactivate:type: customacl_resource: monitoring.monitor_updatelabel: deactivate_monitoricon: removeconfirmation: truelink: activate_link#action_configuration: [ @sinabs_monitoring.datagrid.action_permission_provider, getActivateActionPermissions ]#requirejs.ymlconfig:paths:'oro/datagrid/action/custom-action': 'bundles/sinabsmonitoring/js/datagrid/action/custom-action.js'JavaScript123456789101112131415161718192021222324252627282930/*global define*/define(['./model-action'], function (ModelAction) {'use strict';var CustomAction;/*** Ajax action, triggers REST AJAX request** @export oro/datagrid/action/custom-action* @class oro.datagrid.action.CustomAction* @extends oro.datagrid.action.ModelAction*/CustomAction = ModelAction.extend({defaultMessages: {confirm_title: 'Execution Confirmation',confirm_content: 'Are you sure you want to do this?',confirm_ok: 'Yes, do it',confirm_cancel: 'Cancel',success: 'Action performed.',error: 'Action is not performed.',empty_selection: 'Please, select item to perform action.'}});return CustomAction;});PHP123456789101112131415161718<?phpnamespace Sinabs\MonitoringBundle\Extension\Action\Actions;use Oro\Bundle\DataGridBundle\Extension\Action\Actions\AjaxAction;class CustomAction extends AjaxAction {public function getOptions() {$options = parent::getOptions();$options['frontend_type'] = 'custom';if (empty($options['frontend_handle'])) {$options['frontend_handle'] = 'custom';}return $options;}}PHP1234567891011121314151617181920212223242526272829303132333435<?phpnamespace Sinabs\MonitoringBundle\Datagrid;use Oro\Bundle\DataGridBundle\Datasource\ResultRecordInterface;class ActionPermissionProvider {/*** This method is for another action which works without any problem** @param ResultRecordInterface $record* @return array*/public function getEndAlertePermissions(ResultRecordInterface $record) {$isActive = $record->getValue('end');return array('end_alerte' => is_null($isActive),'view' => true,);}/*** @param ResultRecordInterface $record* @return array*/public function getActivateActionPermissions(ResultRecordInterface $record) {$isActive = $record->getValue('active');return array('activate' => !$isActive,'deactivate' => $isActive,'view' => true,);}}The problem maybe is that I use same link for both action. I just want to toggle the state (a bool) of my entity ans display different icon for the action depend on this state.
July 20, 2016 at 6:21 am #28739Hello.
Please, see how it was done for processes or workflows grid – here is grid configuration and permission provider.
July 21, 2016 at 3:31 am #28740Hello,
I have already seen this example and I have a weird excpetion “type must be defined”. My use case isn’t exactly like this example because I have only one methode activateAction which toggle the state of my entity.
Look at the previous code. I have made like in your example…
I’am not sure but I suppose that the problem happen because I put this action in a RestController and not in FOSRestController. It maybe annotations which are not correctly defined.
Thanks for your help.
PHP123456789101112131415161718192021222324252627282930/*** @Get(* "/monitor/activate/{id}",* requirements={"version"="latest|v1", "id"="\d+"},* defaults={"version"="latest", "_format"="json"}* )** @ApiDoc(description="Activate monitor", resource=true)* @AclAncestor("monitoring.monitor_update")** @param $id** @return Response*/public function activateAction($id) {$em = $this->get('doctrine.orm.entity_manager');$monitor = $em->getRepository('SinabsMonitoringBundle:Monitor')->getMonitorById($id);($monitor->isActive()) ? $monitor->setActive(false) : $monitor->setActive(true);$em->flush();return $this->handleView($this->view(array('successful' => true,), Codes::HTTP_OK));}July 21, 2016 at 9:56 am #28741I think you are seeing this exception – it is triggered if action configuration doesn’t include action type. Please, check content of the configuration that triggers this exception – it might give you some clues.
July 22, 2016 at 1:30 am #28742Hi,
Sorry but I don’t really understand how to check the configuration.
I thought the action type was define in datagrid.yml. Morevover it work fine for another action that I have define, then I don’t understand why this not work for this one.July 22, 2016 at 4:25 am #28743There are a lot of things that might trigger this exception – e.g. incorrect file formatting, other grid with invalid configuration at the same page, some listener that modifies your config etc. So, i’m asking you to debug this case and check what configuration really triggers this error.
March 9, 2017 at 10:26 pm #28744How to Remove GridSetting button from datagrid view?
- AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.