{"id":920,"date":"2017-01-21T16:16:09","date_gmt":"2017-01-21T23:16:09","guid":{"rendered":"http:\/\/www.keganv.com\/?p=920"},"modified":"2017-01-21T16:18:49","modified_gmt":"2017-01-21T23:18:49","slug":"how-to-truncate-datagrid-strings-orocrm-platform","status":"publish","type":"post","link":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/","title":{"rendered":"How To Truncate Datagrid Strings For OroCRM &#038; Platform"},"content":{"rendered":"<p><a href=\"https:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-wrapping-text.png\"><img decoding=\"async\" src=\"https:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-wrapping-text-800x553.png\" alt=\"Datagrid Wrapping Text\" class=\"aligncenter\" \/><\/a><br \/>\nIf you have worked in Oro&#8217;s CRM or their platform, you have likely worked with their datagrids. Depending on your fields being output on a datagrid, a common issue is having long strings of text that wraps, making the datagrid hard to read and plain ole&#8217; messy. I&#8217;m going to show you an easy solution, how to truncate the column text in a datagrid.<br \/>\n<!--more--><\/p>\n<p>Let&#8217;s say you have a simple datagrid that displays information about calls. Let&#8217;s also say that their is a call that has a very long subject and it is wrapping, making your datagrid cluttered. There are two easy ways to solve this issue. The first way we&#8217;re going to look at will be in the <code>select<\/code> statement of the datagrids.yml.<\/p>\n<h4>Using the Select Statement<\/h4>\n<p>If you look at the crm-call-bundle datagrids you&#8217;ll find the following calls-grid. You will see a standard select on the subject property. Most of the time, this is fine, as most subjects won&#8217;t be as long as I am showing in this example. However, you can obviously apply this approach to practically any property on any entity&#8217;s datagrid.<\/p>\n<pre>\r\ndatagrids:\r\n    calls-grid:\r\n        extended_entity_name: %oro_call.call.entity.class%\r\n        acl_resource: oro_call_view\r\n        source:\r\n            type: orm\r\n            query:\r\n                select:\r\n                    - call.id\r\n                    - call.subject\r\n                    - CONCAT(call.phoneNumber, '') as phone\r\n                    - call.callDateTime as dateTime\r\n                from:\r\n                    - { table: %oro_call.call.entity.class%, alias: call }\r\n<\/pre>\n<p>Using the CONCAT function, along with a CASE, WHEN statement, you can check if the string is longer than a certain number of characters and cut it off at any length you want! I chose to use an ellipsis on the end of the string. Easy, right?<\/p>\n<pre>\r\ndatagrids:\r\n    calls-grid:\r\n        extended_entity_name: %oro_call.call.entity.class%\r\n        acl_resource: oro_call_view\r\n        source:\r\n            type: orm\r\n            query:\r\n                select:\r\n                    - call.id\r\n                    - |\r\n                        CONCAT(\r\n                            CASE\r\n                                WHEN call.subject IS NOT NULL AND LENGTH(call.subject) >= 35 THEN\r\n                                    CONCAT(SUBSTRING(call.subject, 0 , 35), '...')\r\n                                ELSE\r\n                                    call.subject\r\n                            END,\r\n                          ''\r\n                        ) as subject\r\n                    - CONCAT(call.phoneNumber, '') as phone\r\n                    - call.callDateTime as dateTime\r\n                from:\r\n                    - { table: %oro_call.call.entity.class%, alias: call }\r\n<\/pre>\n<h4>Using a Twig Template<\/h4>\n<p>The second approach would be defining it under the <code>columns<\/code>. Below is the standard configuration.<\/p>\n<pre>\r\ncolumns:\r\n    subject:\r\n        label: oro.call.subject.label\r\n<\/pre>\n<p>Using a template is more work than using the select statement, however, maybe you have a field where you want to make other custom adjustments to the output, like styling certain words. First, there are a few options you will need to add. The <code>type<\/code> option will be set to twig. The <code>template<\/code> option will point to the actual html.twig file you create for output, we&#8217;ll get to that. The <code>frontend_type<\/code> specifies that it is html. Here is how you can easily truncate the string for the output.<\/p>\n<pre>\r\ncolumns:\r\n    subject:\r\n        label: oro.call.subject.label\r\n        type: twig\r\n        template: OroCallBundle::Datagrid\/subject.html.twig\r\n        frontend_type: html\r\n<\/pre>\n<p>Creating the template is as simple as creating any other twig template. For this example the template would live under the CallBundle&#8217;s <code>Resources\/views\/Datagrid\/<\/code> directory. When making an html template for a datagrid, I always like to check if the value is not null first to avoid any possible errors.<\/p>\n<pre>\r\n{% if value is not null %}\r\n   {{ value|length > 35 ? value[:35] ~ '...' : value }}\r\n{% endif %}\r\n<\/pre>\n<p>Let&#8217;s take a look at what the datagrid will look like now using either of these methods.<\/p>\n<p><a href=\"https:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-truncate-text.png\"><img decoding=\"async\" src=\"https:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-truncate-text-800x377.png\" alt=\"Datagrid Text Truncated\" class=\"aligncenter\" \/><\/a><\/p>\n<p>Ah, room to breathe, that was easy! Let me know if this helped you out with a comment below!<\/p>\n","protected":false},"excerpt":{"rendered":"If you have worked in Oro&#8217;s CRM or their platform, you have likely worked with their datagrids. Depending on your fields being output on a datagrid, a common issue is having long strings of text that wraps, making the datagrid hard to read and plain ole&#8217; messy. I&#8217;m going to show you an easy solution, &#8230; <br\/> <a class=\"view-article btn btn-primary flip pull-left\" href=\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\"><span>View Article<\/span><\/a>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-920","post","type-post","status-publish","format-standard","hentry","category-coding-programming"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Truncate Datagrid Strings For OroCRM &amp; Platform | KeganV<\/title>\n<meta name=\"description\" content=\"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Truncate Datagrid Strings For OroCRM &amp; Platform | KeganV\" \/>\n<meta property=\"og:description\" content=\"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\" \/>\n<meta property=\"og:site_name\" content=\"KeganV\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-21T23:16:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-01-21T23:18:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-wrapping-text-800x553.png\" \/>\n<meta name=\"author\" content=\"Kegan V.\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kegan V.\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\"},\"author\":{\"name\":\"Kegan V.\",\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"headline\":\"How To Truncate Datagrid Strings For OroCRM &#038; Platform\",\"datePublished\":\"2017-01-21T23:16:09+00:00\",\"dateModified\":\"2017-01-21T23:18:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\"},\"wordCount\":429,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"articleSection\":[\"Coding &amp; Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\",\"url\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\",\"name\":\"How To Truncate Datagrid Strings For OroCRM & Platform | KeganV\",\"isPartOf\":{\"@id\":\"https:\/\/www.keganv.com\/#website\"},\"datePublished\":\"2017-01-21T23:16:09+00:00\",\"dateModified\":\"2017-01-21T23:18:49+00:00\",\"description\":\"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.keganv.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Truncate Datagrid Strings For OroCRM &#038; Platform\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.keganv.com\/#website\",\"url\":\"https:\/\/www.keganv.com\/\",\"name\":\"KeganV\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.keganv.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276\",\"name\":\"Kegan V.\",\"logo\":{\"@id\":\"https:\/\/www.keganv.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.keganv.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Truncate Datagrid Strings For OroCRM & Platform | KeganV","description":"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/","og_locale":"en_US","og_type":"article","og_title":"How To Truncate Datagrid Strings For OroCRM & Platform | KeganV","og_description":"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.","og_url":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/","og_site_name":"KeganV","article_published_time":"2017-01-21T23:16:09+00:00","article_modified_time":"2017-01-21T23:18:49+00:00","og_image":[{"url":"http:\/\/www.keganv.com\/wp-content\/uploads\/datagrid-wrapping-text-800x553.png"}],"author":"Kegan V.","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kegan V.","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#article","isPartOf":{"@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/"},"author":{"name":"Kegan V.","@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"headline":"How To Truncate Datagrid Strings For OroCRM &#038; Platform","datePublished":"2017-01-21T23:16:09+00:00","dateModified":"2017-01-21T23:18:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/"},"wordCount":429,"commentCount":0,"publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"articleSection":["Coding &amp; Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/","url":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/","name":"How To Truncate Datagrid Strings For OroCRM & Platform | KeganV","isPartOf":{"@id":"https:\/\/www.keganv.com\/#website"},"datePublished":"2017-01-21T23:16:09+00:00","dateModified":"2017-01-21T23:18:49+00:00","description":"Are your datagrids messy with long text? Learn two easy ways to truncate datagrid strings in OroCRM and in Oro Platform.","breadcrumb":{"@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.keganv.com\/how-to-truncate-datagrid-strings-orocrm-platform\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.keganv.com\/"},{"@type":"ListItem","position":2,"name":"How To Truncate Datagrid Strings For OroCRM &#038; Platform"}]},{"@type":"WebSite","@id":"https:\/\/www.keganv.com\/#website","url":"https:\/\/www.keganv.com\/","name":"KeganV","description":"","publisher":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.keganv.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/412e7755f594475dc403b6d774b80276","name":"Kegan V.","logo":{"@id":"https:\/\/www.keganv.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.keganv.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/920"}],"collection":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/comments?post=920"}],"version-history":[{"count":15,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/920\/revisions"}],"predecessor-version":[{"id":940,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/posts\/920\/revisions\/940"}],"wp:attachment":[{"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/media?parent=920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/categories?post=920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.keganv.com\/api\/wp\/v2\/tags?post=920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}