PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] How to create a custom action column in kartik gridview

 March 08, 2022     gridview, kartik-v, php, yii, yii2     No comments   

Issue

I am trying to create a column that displays a glyphicon. The glyphicon will link to an url which allows the user to download a file. Any help would be massively appreciated. Current code is as follows:

GridView::widget([
'dataProvider' => $dataProvider,
'pager' => [
    'class' => 'common\widgets\Pagination',
],
'columns' => [
    ['class' => 'yii\grid\SerialColumn'],
    [
        'label' => 'Date',
        'attribute' => 'call_datetime',
        'format' => 'date',
    ],
    [
        'label' => 'Time',
        'attribute' => 'call_datetime',
        'format' => 'time',

    ],
    'call_from',
    'call_to',
    'duration',
    'call_type',
    'extension',

    [
        'label' => 'File',
        'attribute' => 'fname',
        'value' => 'callRecFiles.fname',
    ],

It is the last attribute 'fname' that the user will be downloading.


Solution

Change your fname field array to:

[
    'label' => 'File',
    'attribute' => 'fname',
    'value' => function($model) {
         //here create glyphicon with URL pointing to your action where you can download file, something like 
         return $model->callRecFiles ? Html::a('Download', ['myController/download-action', 'fname' => $model->callRecFiles->fname]) : null;
    }
],

And prepare proper action to allow user to download file.



Answered By - Yupik
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing