I'm trying to create a modal box that will allow the user to filter and search a grid. This is going to be so the user can look up information inside another database whilst filling in the form of another.
I can create the modal fine, but it's the rendering that's the problem.
Currently, the code inside the modal in _form.php is as follows:
echo $this->renderPartial('/students/_find', array('model'=>Students::model()));
This is fine, and renders the grid fine. _find.php is as follows:
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView',array(
'id'=>'students-grid',
'type' => 'striped bordered',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns' => array(
array('name'=>'studentname', 'header'=>'Name'),
array('name'=>'studentgender', 'header'=>'Gender'),
array('name'=>'studentyear', 'header'=>'Year Group'),
array('name'=>'studenthouse', 'header'=>'House'),
),
)); ?>
However, searching inside that grid does nothing. I can click on the headers and it sorts, but typing in the search boxes under the headings does nothing. No errors are produced in JS, and it the spinner appears for a short while then disappears, but no actual filtering has occurred.
Changing the line in _form to:
echo $this->renderPartial('/students/_find', array('model'=>Students::model()),false,true);
Makes a difference. The first thing I notice is that the JS for _form is broken, because I use Select2 in _form, and they do not load (TypeError: jQuery(...).select2 is not a function
). When I open the modal (which renders the grid fine), and search, the spinner just keeps spinning and nothing happens.
Checking the console, I see the following error:
too much recursion
Chrome is more helpful:
Uncaught RangeError: Maximum call stack size exceeded
Adding Yii::app()->clientscript->scriptMap['*.js'] = false;
to the modal just gets rid of all JS. However, looking at the network trace, it does look like my JS is being called twice. So it seems there may be a conflict of scripts
The next step would be to write this as a widget, but I am unsure how to do it. Perhaps AJAX would be the way to go, but I am unsure of how to proceed with that.
try changing to
echo $this->renderPartial('/students/_find', array( 'model'=>new Students('search') ));