PDA

View Full Version : How to get DataStore



casic
27 Jan 2011, 12:39 PM
Hello ,
I want to use example below

var store = new Ext.data.ArrayStore({
proxy : new Ext.data.MemoryProxy(),
fields : ['hasEmail', 'hasCamera', 'id', 'name', 'price', 'screen', 'camera', 'color', 'type', 'reviews', 'screen-size'],
sortInfo: {
field : 'name',
direction: 'ASC'
}
});

store.loadData([
[true, false, 1, "LG KS360", 70, "240 x 320 pixels", 2, "Pink", "Slider", 359, 2.400000],
[true, true, 2, "Sony Ericsson C510a Cyber-shot", 180, "320 x 240 pixels", 3.2, "Future black", "Candy bar", 11, 0.000000],
[true, true, 3, "LG PRADA KE850", 155, "240 x 400 pixels", 2, "Black", "Candy bar", 113, 0.000000],
[true, true, 4, "Nokia N900 Smartphone 32 GB", 499, "800 x 480 pixels", 5, "Black", "Slider", 320, 3.500000],
[true, false, 5, "Motorola RAZR V3", 65, "96 x 80 pixels", 0.3, "Silver", "Folder type phone", 5, 2.200000],
[true, true, 18, "LG Xenon GR500", 50, "240 x 400 pixels", 2, "Red", "Slider", 658, 2.800000],
[true, false, 19, "BlackBerry Curve 8900 BlackBerry", 135, "480 x 360 pixels", 3.2, "Silver", "Candy bar", 21, 2.440000],
[true, false, 20, "Samsung SGH U600 Ultra Edition 10.9", 135, "240 x 320 pixels", 3.2, "Rainbow", "Slider", 169, 2.200000]
]);


, but i want to get data with PHP script.
Please help to make this script running.
By the way this is from examples EXTJS "Animated DataView" .

http://dev.sencha.com/deploy/dev/examples/view/multisort-dataview.html

Thanks in advance.

Seana
27 Jan 2011, 1:14 PM
The easiest way would likely be use PHP to build a JSON representation of your data and then consume that JSON with a Ext.data.JsonReader (http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.JsonReader)

casic
27 Jan 2011, 1:17 PM
I have tried , but can't get working !!!
That is why i looking for help.

Seana
27 Jan 2011, 1:29 PM
Where is the code with the reader, that's going to make it easier to help you solve the issue.

you could also try changing the store to a JsonStore something similar to

var store = new Ext.data.JsonStore({
url: 'getjson.php',
root: 'images',
idProperty: 'id',
fields : [{
name: 'hasEmail', type: 'boolean'
},{
name: 'hasCamera', type: 'boolean'
},{
name: 'id', type: 'int'
},'name',{
name: 'price', type: 'float'
}, 'screen', 'camera', 'color', 'type', 'reviews', 'screen-size'],
});

Note: this is untested it's more for example

Seana
27 Jan 2011, 1:39 PM
I should have mentioned with the above code you would just use

store.load();
instead of

store.loadData([
[true, false, 1, "LG KS360", 70, "240 x 320 pixels", 2, "Pink", "Slider", 359, 2.400000],
[true, true, 2, "Sony Ericsson C510a Cyber-shot", 180, "320 x 240 pixels", 3.2, "Future black", "Candy bar", 11, 0.000000],
[true, true, 3, "LG PRADA KE850", 155, "240 x 400 pixels", 2, "Black", "Candy bar", 113, 0.000000],
[true, true, 4, "Nokia N900 Smartphone 32 GB", 499, "800 x 480 pixels", 5, "Black", "Slider", 320, 3.500000],
[true, false, 5, "Motorola RAZR V3", 65, "96 x 80 pixels", 0.3, "Silver", "Folder type phone", 5, 2.200000],
[true, true, 18, "LG Xenon GR500", 50, "240 x 400 pixels", 2, "Red", "Slider", 658, 2.800000],
[true, false, 19, "BlackBerry Curve 8900 BlackBerry", 135, "480 x 360 pixels", 3.2, "Silver", "Candy bar", 21, 2.440000],
[true, false, 20, "Samsung SGH U600 Ultra Edition 10.9", 135, "240 x 320 pixels", 3.2, "Rainbow", "Slider", 169, 2.200000]
]);

and your JSON would be formated like...


{
images:[
{
hasEmail: true,
hasCamera: false,
id: 20,
name: "Samsung SGH U600 Ultra Edition 10.9",
price: 135.00,
screen: "240 x 320 pixels",
camera: 3.2,
color: "Rainbow",
type: "Slider",
reviews: 169,
screen-size: 2.200000
},{....}
]
}

casic
27 Jan 2011, 1:45 PM
thanks! I Will test it.

casic
27 Jan 2011, 2:14 PM
Don't work. Some error in DataView . At first glance store is the same , is not working .

Seana
27 Jan 2011, 2:19 PM
Don't work. Some error in DataView . At first glance store is the same , is not working .

What's the Error?

steffenk
27 Jan 2011, 2:45 PM
learn to explore it yourself. Add Firebug console, view the JS errors, view the request and the response, it's all in helping you to correct your code.

casic
28 Jan 2011, 1:30 AM
What's the Error?
Webpage error details




Message: 'null' is null or not an object
Line: 102
Char: 17
Code: 0
URI: http://localhost/ext-3.3.0/examples/ux/DataViewTransition.js

casic
28 Jan 2011, 2:00 AM
When store is empty - there is no error. But when store loaded with JsonStore like code above get this error .
Please HELP !!!

casic
28 Jan 2011, 3:29 AM
I have made some probes , and i find when coment out this lines , code work

plugins : [
new Ext.ux.DataViewTransition({
duration : 550,
idProperty: 'id'
})
],

I mean that DataView load and show all items corect.
But when this plugin is ON is not working like original code with ArrayStore

casic
28 Jan 2011, 3:54 AM
Thanks a lot !!!
Finaly working .
Just the plugin isn not work.

Seana
28 Jan 2011, 6:35 AM
Thanks a lot !!!
Finaly working .

I'm glad to hear you got it working.

A few suggestions for going forward, as steffenk said, you should really get into the habit of using a "good" JavaScript/DOM debugger. Based on the error message you posted you are likely using IE6/7 if that is the case I would highly recommend using Firefox + FireBug, Chrome or Safari to help in the debugging of scripts.

Not only do they give you a more meaningful error message but in most cases will give you stack traces, the ability to proto-type code with the "console," set break points/variable watches and allow DOM inspection, to name a few of the most used features.