Revision #144                                    has been created by  Gerhard Liebenberg                                    on Oct 16, 2013, 6:59:14 AM with the memo:
 Gerhard Liebenberg                                    on Oct 16, 2013, 6:59:14 AM with the memo:
                                
                                
                                    Typo                                
                                                                    « previous (#143)                                                                                            
                            Changes
                            
    Title
    unchanged
    Dynamic parent and child CGridView on single view. Using $.ajax to update child gridview via controller, after row in parent gridview was clicked.
    Category
    unchanged
    Tutorials
    Yii version
    unchanged
    
    Tags
    unchanged
    dynamic, parent-child, CGridView, ajax, many_many, jquery event delegation, loading.gif, CGridView sorting and filtering on default and related models, sort dropDownList, sending selected dropDownList rows to controller, extract data from CGridView and pa
    Content
    changed
    [...]
If you want to retrieve the child records for a certain parent record, then you would NORMALLY just "read" one of the parent model's relations to the child model. This is called "Relational Query" in the Yii documentation.
However, in this example, we do not simply want to display the child records. No, we need much more. We need to be able to manipulate (sort/search/page and maybe even view/update/delete) the child records in their own CGridView. But to do all this with the child records in their own CGridView, they will need their own dataprovider.
So we do this by getting the child records DIRECTLY (not via relational query) from their own model, where their own dataprovider can be generated.
So (in short) the process works like this:[...]
And that is exactly why - in the search() function - we can have a statement like:
 
 $criteria->compare('field1', $this->field1, false);
 
 
OR
 
 
 $criteria->compare('field1', $parent_model->field1, false);
This statement instructs the dataprovider to only include records where[...]
/* Url Problems: 
		If you receive 404 errors about the request not finding the
		correct page or 'request failed' etc., then the aboveyour url is 
		probably not 
getting formatt
inged	correctly. (Use Firebug to see if the
		generated url contains both the controller and the action names.)
		However, this error sometimes results from code in a totally[...]
include the action's name in the url in the browser's address bar.
		I guess the ajax-request uses the same url in the address bar to
 
		generate its own url.
 
		So make sure your url in the browser's address bar contains both 
 
		the controller and action namesThis gave me a hint, than maybe, my url is not formatted correctly.*/
		request.done(function(response) { 
			try{
				/*since you are updating innerHTML, make sure the
				received data does not contain any javascript -[...]