ajaxlink in cgridview; Error undefined is not a function in yiigridview.js

1.2k views Asked by At

I'm receiving the error
Uncaught TypeError: undefined is not a function jquery.yiigridview.js

I have tried several ways, but I don't think I am doing this correctly. I currently have :

  $this->widget ( 'bootstrap.widgets.TbGridView', array (
  'type' => 'condensed',
  'id'=>'inq',
  'dataProvider' => $dataProvider,
  'template' => '{items}{pager}',
  'columns' => array (
        array(
        'header'=>'',
        'type'=>'raw',
        'htmlOptions'=>array('style'=>'width:30px'),
        'value'=>function($data,$row){
        if($data->message_target_read == "Read")
        return CHtml::ajaxLink('<img src="'.Yii::app()->baseUrl.'/images/site/star-read.png">',
                  Yii::app()->createUrl("controller/action", array("id"=>$data->id)),
                  array("complete"=>"function(){
                  $.fn.yiiGridView.update('inq', {
                  type: 'POST',
                  url: $(this).attr('href'),
                  success: function() {
                  $.fn.yiiGridView.update('inq');}
                  });return false;}"));

I also tried with chtml::link using a class and get Yii::app()->clientScript->registerCoreScript('class' but that kept redirecting the entire page. I also tried just doing this

CHtml::ajaxLink("<img>",Yii::app()->createUrl("controller/action", array("id"=>$data->id)),array( 
type: 'POST',
url: $(this).attr('href'),
success: function() {
$.fn.yiiGridView.update('inq');
                                }
1

There are 1 answers

1
Hearaman On BEST ANSWER

You missed the structure of CHtml::ajaxLink(). You have closed it after custom ID array("id"=>$data->id)). This can cause functionality failure.

Please check below structure.

<?php
$dataProvider = new CActiveDataProvider('FlightSearch');
$this->widget('bootstrap.widgets.TbGridView', 
array(
    'type' => 'striped bordered condensed',
    'id' => 'inq',
    'dataProvider' => $dataProvider,
    'template' => "{items}{pager}",
    'columns' =>
    array
    (
        array('name' => 'column1', 'header' => 'Column Title'),
        array
        (
            'header' => '',
            'type' => 'raw',
            'htmlOptions' => array('style' => 'width:30px'),
            'value' => function($data, $row) 
            {
                if($data->message_target_read == "Read")
                {
                    return CHtml::ajaxLink('a link', 
                    Yii::app()->createUrl("controller/action", 
                    array("id" => $data->id), 
                    array("complete" => "function()
                    { 
                          /*=====Your jQuery functionality start=====*/
                          $.fn.yiiGridView.update('inq', {
                          type: 'POST',
                          url: $(this).attr('href'),
                          success: function() 
                          {
                                $.fn.yiiGridView.update('inq');
                          }
                          });return false;}"))
                          /*=====Your jQuery functionality end=====*/
                    );
                }
            })),
));
?>