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.

yii\helpers\StringHelper;

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

[
‘class’ => ‘kartik\grid\EditableColumn’,
‘attribute’=>’company_id’,
‘vAlign’=>’middle’,
‘width’=>’250px’,
‘editableOptions’=> function ($model) use ($customerFilter) {
return [
‘header’=>’Customer’,
‘size’=>’md’,
‘format’ => ‘link’,
‘asPopover’ => true,
‘displayValueConfig’ => $customerFilter,  //This is where your value is displayed
‘inputType’ => Editable::INPUT_SELECT2,
‘options’=>[
‘theme’ => ‘krajee’,
‘data’ => $customerFilter,
‘pluginOptions’=>[
‘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], [
‘title’=>$customerFilter[$model->company_id]]),

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

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s