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

How to fix TypeError: jQuery(…).editable is not a function in yii2 kartik editable gridview issue

You could have a problem described below

This has been copied from https://disqus.com/home/discussion/krajee/not_found_404_kartik_439/

I am having a problem with the editable column in a gridview, I was hopingfor a point in the right direction to resolve. When I add a row in a blank grid via ajax, I reload the grid using pjax. On the Pjax reload the editable column comes up as a button and has no events triggered. Firebug reports the following error.

TypeError: jQuery(…).editable is not a function.

On a page reload after adding the first row everything works as expected. Adding a second line to the grid everything works as expected. The problem only occurs when the first row is added and the grid refreshed via pjax.

This can be fixed by loading the assets manually .

Just put this on the top of your view and it will work fine.

use kartik\editable\EditableAsset;

EditableAsset::register($this);

use kartik\editable\EditablePjaxAsset;

EditablePjaxAsset::register($this);

use kartik\popover\PopoverXAsset;

PopoverXAsset::register($this);

I have also reported it kartik here where more info can be found regards this issue.

https://github.com/kartik-v/yii2-dynagrid/issues/97

Have a happy Yii2 programming!