function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
XiscoXisco 

Fill in data in ExtJs Panel Grid

 

Hi,

 

I'm new in the plataform - I having some problems to fill in data in a ExtJs Panel Grid - When I got back the String in JSON format I define my Ext.Data.Model - I have some lookup up relations in my Query and I don't know how to define them in my Ext.Data.Model, the fields that don't have look up relationships work fine but I cant get the value from the ones that have it

 

If somebody can help me with this issue will be great!

 

Many thanks

Xisco :)

 

Here is my code:

 

<script type="text/javascript">

		Ext.ns("Ext.Classing"); //Defining a namespace is best practice in ExtJS
			
		
		Ext.onReady(function(){ //This is a execution point
			
			//This is to create InCourse panel
		    var InCoursePanel = new Ext.create('Ext.Classing.InCoursePanel', {   
		            renderTo: InCourse,
		            title : 'Students to place'
		        });
		        		    
	
	        //This method is used to call our controller method
	        Controller_ClassingSimpleGrid.getAllBookings(function(result, er){	        							
						                var res = Ext.decode(result);
						                store.loadData(res.Records);
	            					}, {escape:false});
   		});
   		
   		   		
   		//Defining a model, which is like an object
   		Ext.define('ClassingStudentsModel', {
	        extend	: 'Ext.data.Model',
	        fields	:[
			            {name: 'Id', type: 'string'},
			            {name: 'Name', type: 'string'},
			            {name: 'Gender__c', type: 'string'},
			            {name: 'Nationality__c', type: 'string'}
	    			  ]
	    });   		
   		
   		//Create a store, which is like collection of records with sorting and grouping capability
   		var store = Ext.create('Ext.data.Store', { 
	                        model 		: 'ClassingStudentsModel', //Associate your store with Model
	                        proxy 		: {
				                            type 	: 'memory',
				                            reader	: {
			                                	type : 'json',
				                          	}
	                       				  }
	                    });
   		
   		//Defining a panel in order to display our data
   		Ext.define('Ext.Classing.InCoursePanel', {
	        extend		: 'Ext.grid.Panel',
	        alias 		: 'widget.InCoursePanel',
	        name 		: 'InCoursePanel',
	        columnLines : true,
	        autoScroll	: true,
	        singleSelect: false,	        
	        border		: true,
	        height		: 300,
	        width		: 250,
	        store		: store, //Associate with our store
	        stripeRows  : true,
	        multiSelect : true,
	        columns 	: [ //Define the required columns
		                    {
		                        text 		: 'Id',
		                        dataIndex	: 'Id',
		                        flex		: 0.3
		                        //hidden      : true,
		                        //hideable    : false
		                    },
		                    {
		                        text 		: 'Name',
		                        dataIndex 	: 'Name',
		                        flex 		: 0.3
		                    },
		                    {
		                        text 		: 'Gender',
		                        dataIndex 	: 'Gender__c',
		                        flex 		: 0.3
		                    },
		                    {
		                        text 		: 'Nationality',
		                        dataIndex 	: 'Nationality__c',
		                        flex 		: 0.3
		                    }
		            	],
		});
global class Controller_SimpleGrid { 
    
@RemoteAction
    global static String getAllBookings() //Need to define as a remote action as we will be calling this through javascript
    {
        List<Booking__c> bookings = [Select Id, Enrolment__r.Account__r.Name, Enrolment__r.Account__r.Gender__c, 
                                                Enrolment__r.Account__r.Nationality__c
                                     From Booking__c
                                     Where Enrolment__r.Account__r.RecordType.Name = 'Student'];
                                     
    	system.Debug('Im here!!!!');                                     
                                     
        String JSONString = JSON.serialize(bookings);//This is how we can serailize our response into JSON format
        
        
        system.debug(JSONString);
        
        return '{\"Records\":' +JSONString+', \"error\": \"null\", \"status\":\"SUCCESS\", \"count\":\"' + bookings.size() + '\" }';
    }


}

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
XiscoXisco

Hooray!

 

I've just found the problem. 

 

By adding a Group by in the SOQL query you get a good  format for the JSON string and the the Ext.Data.Model is as simple as you can see above in the code.

 

Select Id, Enrolment__r.Account__r.Name, Enrolment__r.Account__r.Gender__c,Enrolment__r.Account__r.Nationality__c
From Booking__c
Where Enrolment__r.Account__r.RecordType.Name = 'Student'
group by Id, Enrolment__r.Account__r.Name, Enrolment__r.Account__r.Gender__c,Enrolment__r.Account__r.Nationality__c

 

 

 

Cheers 

Xisco

 

 

All Answers

XiscoXisco

Hooray!

 

I've just found the problem. 

 

By adding a Group by in the SOQL query you get a good  format for the JSON string and the the Ext.Data.Model is as simple as you can see above in the code.

 

Select Id, Enrolment__r.Account__r.Name, Enrolment__r.Account__r.Gender__c,Enrolment__r.Account__r.Nationality__c
From Booking__c
Where Enrolment__r.Account__r.RecordType.Name = 'Student'
group by Id, Enrolment__r.Account__r.Name, Enrolment__r.Account__r.Gender__c,Enrolment__r.Account__r.Nationality__c

 

 

 

Cheers 

Xisco

 

 

This was selected as the best answer
Emtecinc developer049388157163885804Emtecinc developer049388157163885804
Some best practices for Using Extjs with Salesforce
http://extjswithsandeesh.blogspot.in/2012/07/extjs-with-salesforce-best-practices.html
benkurianbenkurian
hi All

how to Do the CRUD functionality in this extjs by using java script remoting