This topic contains 5 replies, has 2 voices, and was last updated by shreyas 7 years, 8 months ago.
- Topic
Hi Team,
I have a requirement wherein i need to display a second datagrid(leadfilterby-account) wherein it display lead details for a specific account number that would be obtained from 1st datagrid (accounts-grid2) row click in same twig with no page reload.
Here for each Account row by its account Id field i am able to get the Account Id. So once a Row is clicked i am able to get its id & calling a controller with AccountId which would be given as parameter to a Query which gives me response . The response i am obtaining is correct & i am able to get back in Twig. But i need The Response to be as a Lead Datagrid(leadfilterby-account) which could get displayed & needs changed Lead Data each time a row is clicked from above Datagrid(accounts-grid2) without any reload of page.Please find the below Datagrid code for accounts-grid2 & leadfilterby-account given below:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899accounts-grid2:extended_entity_name: %orocrm_account.account.entity.class%inline_editing:enable: trueacl_resource: orocrm_account_viewsource:type: ormquery:select:- a.id- a.name- a.firstName as FirstName- a.lastName as LastName- accStatus.label as AccountStatus- a.id as accIdfrom:- { table: %orocrm_account.account.entity.class%, alias: a }join:left:- { join: a.defaultContact, alias: defaultContact }- { join: defaultContact.emails, alias: defaultContactEmail, conditionType: 'WITH', condition: 'defaultContactEmail.primary = true' }- { join: defaultContact.phones, alias: defaultContactPhone, conditionType: 'WITH', condition: 'defaultContactPhone.primary = true' }- { join: a.owner, alias: accountOwner }- { join: a.accountStatus, alias: accStatus }properties:id: ~owner: ~columns:accId:label: Account Id#frontend_type: htmlrenderable: falseFirstName:label: orocrm.account.firstName.labelLastName:label: orocrm.account.lastName.labelAccountStatus:label: orocrm.account.accountStatus.labelsorters:columns:FirstName:data_name: FirstNameLastName:data_name: LastNameAccountStatus:data_name: AccountStatusfilters:columns:FirstName:type: stringdata_name: a.firstNameLastName:type: stringdata_name: a.lastNamemass_actions:merge:type: mergeentity_name: %orocrm_account.account.entity.class%data_identifier: a.idoptions:entityHint: accountexport: trueentity_pagination: trueleadfilterby-account:acl_resource: orocrm_sales_lead_viewsource:type: ormquery:select:- l.id- l.name- l.firstName- l.lastName- acc.id as accidfrom:- { table: %orocrm_sales.lead.entity.class%, alias: l }join:left:- { join: l.owner, alias: own }- { join: own.owner, alias: bunit }- { join: l.account, alias: acc }where:and:- acc.id = :accountidbind_parameters:- accountidcolumns:lastName:label: orocrm.sales.lead.last_name.labelfirstName:label: orocrm.sales.lead.first_name.labelaccid:label: 'account id'properties:id: ~owner: ~Here in Account grid(accounts-grid2) i am using an hidden field(accId) to get account Id to be used in Click Event to get Id through Jquery.
Please find code for Controller (Loc: ProjDir\src\Custom\Bundle\OroBundle\Controller\CustomRoleController.php) function given below to render these datagrids:
123456789101112131415161718192021222324252627282930313233/*** @Route("/acctypes", name="customroles_accchecknow")**/public function acccheckAction(){return $this->render('CustomOroBundle:CustomRole:accountgrid.html.twig');}/*** @Route("/leadcheck", name="leadcheck_foracccheck")**/public function leadbasedonacccheckAction(){$accid = 24;return $this->render('CustomOroBundle:CustomRole:leadgrid.html.twig',array('accountid' => $accid));}/*** @Route("/leadcheckusingajax", name="leadcheck_foracccheckajx")**/public function leadbasedonacccheckajxAction(){$accid = $_POST['accid'];$em = $this->getDoctrine()->getEntityManager();$connection = $em->getConnection();$qry = $connection->prepare("SELECT first_name,last_name,account_id FROM orocrm_sales_lead where account_id = $accid ");$qry->execute();$resdata = $qry->fetchAll();return new Response(json_encode($resdata));//return $this->render('CustomOroBundle:CustomRole:leadgrid.html.twig',array('accountid' => $accid));}please find the twig files below for Account grid & Lead Grid:
ProjDir\src\Custom\Bundle\OroBundle\Resources\views\CustomRole\accountgrid.html.twig
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253{% extends 'OroUIBundle:actions:index.html.twig' %}{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}{% set pageTitle = 'Account Details' %}{% block head_script %}{{ parent() }}{% block javascripts %}<script type="text/javascript">require(['jquery'], function ($) {$(document).ready(function(){function getFun(){if($( ".tstJqry table tbody tr" )){$('.tstJqry table tbody tr').click(function(e){//e.stopImmediatePropagation();var getaccId = $(this).closest('tr').find('.grid-body-cell-accId').html();//alert('accId');//alert(getaccId);$.ajax({url: "{{ path('leadcheck_foracccheckajx') }}",type: 'POST',data: {accid: getaccId},success: function (response) {console.log(response);//alert(response);$('.datagrid2').html(response);}});return false;});} else {window.setTimeout(getFun, 1000);};};window.setTimeout(getFun,1000);});});</script>{% endblock %}{% endblock %}{% block content %}<div><h2> {{ 'Test Account'|trans }}</h2></div><div class='tstJqry datagrid1 acc_grid'>{{ dataGrid.renderGrid('accounts-grid2') }}</div><div class="datagrid2 lead_grid"></div>{% endblock content %}Here in the above twig file i need to show the leadgrid.html.twig’s Datagrid i.e(leadfilterby-account) with a dynamic parameter to it as accountId that gets generated each time on Account grid row click. So once clicked only the
Datagrid2(leadfilterby-account) has to be refreshed with the new values corresponding to account clicked without loading the page.This is where i am stuck on how to get.2)
ProjDir\src\Custom\Bundle\OroBundle\Resources\views\CustomRole\leadgrid.html.twig12345678910111213141516171819{% extends 'OroUIBundle:actions:index.html.twig' %}{% import 'OroDataGridBundle::macros.html.twig' as dataGrid %}{% set pageTitle = 'Account Details' %}{% block head_script %}{{ parent() }}{% block javascripts %}<script type="text/javascript"></script>{% endblock %}{% endblock %}{% block content %}<div><h2> {{ 'Test Account'|trans }}</h2></div><div class='tstJqry'>{{ dataGrid.renderGrid('leadfilterby-account',{accountid: accountid}) }}</div>{% endblock content %}I could use the response currently i am getting to build a table similar to that done in a Datagrid & use css for UI . But the issue is i need it to be a Datagrid itself since it provides most of function like sorting,filtering,deleting,pagination , editing & viewing . So Please need help on how to go above with this.
i looked at some of references given below but could not get from where to start & no clear understanding on what to do. In some places – actions are used & some of them with mediator in js files which i am not aware about at all & dont even know whether these would be used in getting solution for the requirement.
custom-datagrid-action
orocrm-create-custom-grid-action-technique-and-secret
advanced_grid_configuration.md#problem-4Please find below the Account Grid View(accounts-grid2) where i am able to get JSON response for Lead Values shown in FIrebug which are with Account Id -31:
Please find below another datagrid-(leadfilterby-account) view screenshot that has a hardcoded value for account Id passed from controller(In example AccId is 24) from function leadbasedonacccheckAction() shown in above Controller code:
Kindly need help if any resource or any suggestions on how to go about with to solve this issue .
Thanks & Regards,
Shreyas S
The forum ‘OroCRM’ is closed to new topics and replies.