2

How to add content limit in custom grid column in magento 2.is anyone have any idea..ie nothing string limit in column i found below like this we can do it in magento 1

$this->addColumnAfter('addons', array(
            'header' => Mage::helper('sales')->__('Addons'),
            'filter'    => false,
            'sortable'  => false,            
            'index' => 'addons',
            'type'  => 'text',
            'string_limit'  => '500', /* added for content limit */

        ), 'billing_name'); 

enter image description here

1
  • Grid is UI component or form field.? Commented Sep 12, 2018 at 11:58

1 Answer 1

0

According to below code you can use string_limit in Magento2 like as you are using in Magento1 with Render

namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;

/**
 * Backend Grid Renderer
 */
class Longtext extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
    /**
     * Render contents as a long text
     *
     * Text will be truncated as specified in string_limit, truncate or 250 by default
     * Also it can be html-escaped and nl2br()
     *
     * @param \Magento\Object $row
     * @return string
     */
    public function render(\Magento\Object $row)
    {
        $truncateLength = 250;
        // stringLength() is for legacy purposes
        if ($this->getColumn()->getStringLimit()) {
            $truncateLength = $this->getColumn()->getStringLimit();
        }
        if ($this->getColumn()->getTruncate()) {
            $truncateLength = $this->getColumn()->getTruncate();
        }
        $text = $this->filterManager->truncate(parent::_getValue($row), array('length' => $truncateLength));
        if ($this->getColumn()->getEscape()) {
            $text = $this->escapeHtml($text);
        }
        if ($this->getColumn()->getNl2br()) {
            $text = nl2br($text);
        }
        return $text;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.