Reputation: 237
Trying to understand how data modeling works in ExtJS.
So, my server returns such data in two seperate ajax calls.
First call, getProducts() returns something like that:
id id_category name description
Second ajax call, getCategories() returns :
id name
Of course I want to display 'products' data in table. I can already do that using Model and Store, but in my table I still see id_category and I want to display category_name in there.
I've tried to do that using Model Associations and hasOne relationship, but it doesn't seem to work, because data is fethed in two seperate ajax calls.
I figured it out that I need to use 'render' function for each column. (Am I right ?) I can do that too, but right now every column is making ajax call and I wan to get category names with one ajax call.
In jQuery I would simply do that. I would first run getProducts(), then getCategories() and iterate thru all categories to find proper category name.
Don't have a clue how to do that in Sencha (but of course pattern should be similar).
I would really appreciate if anyone can help me understand that.
Upvotes: 1
Views: 56
Reputation: 361
You are right. You need to use renderer in the column of id_category. I assume that you have 2 seperate stores, for eg: store_products and store_category. You fill the data with ajax calls. (No need of hasOne relationship). store_products is used to display products data in grid/table. Now in the renderer what you can do is ,
{
text : 'Category'
renderer : function(val) {
{
var category_record = store_category.findRecord("id_category", val, 0, false, false, true);
if(category_record){
return category_record.get('category_name');
}
else{
return val;
}
}
dataIndex : 'id_category',
}
So you are not calling ajax method in store_category every time for each row, instead, the store is already populated before displaying data. And while rendering the column, simple find the record and return the name instead of id.
Upvotes: 1