How to truncate value in yii2 kartik editable option

You possibly use the following in your view

use kartik\grid\GridView;
use kartik\dynagrid\DynaGrid;
use kartik\dynagrid\DynaGridStore;
use kartik\editable\Editable;
use kartik\select2\Select2 ;
use yii\widgets\Pjax;
use kartik\cmenu\ContextMenu;

You will also need use also the one below. This contain truncate function.


So in your view you might have the following under the column definition

‘class’ => ‘kartik\grid\EditableColumn’,
‘editableOptions’=> function ($model) use ($customerFilter) {
return [
‘format’ => ‘link’,
‘asPopover’ => true,
‘displayValueConfig’ => $customerFilter,  //This is where your value is displayed
‘inputType’ => Editable::INPUT_SELECT2,
‘theme’ => ‘krajee’,
‘data’ => $customerFilter,
‘allowClear’ => true,

then do the following:

replace the displayValueConfig with displayValue

//’displayValueConfig’ => $customerFilter,  //This is where your value is

then add necessary things and use your filter array.

This will truncate a value nicely to 30 characters and display all characters on hover.

‘displayValue’ => Html::a(StringHelper::truncate($customerFilter[$model->company_id], 30, $suffix = ‘…’),[‘tickets/view’,’id’ => $model->ticket_id], [

Hope you enjoy it and let me know if you need any more help with this 🙂



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s