PDA

View Full Version : add to dataview



vivendi
5 Jun 2009, 4:34 AM
Suppose i've created a simple dataView, with no content in it yet.

What do i have to do in order to add new items to it..?? The var to the dataView function is also called dataView.

var dataView = new Ext.DataView()... etc..

So is there something like:

dataView.add(imageurl); or something? To add a new image to the dataview..?

5 Jun 2009, 5:43 AM
DataViews are bound to a store. to add and remove items, you add or remove Records to and from a Store.

vivendi
5 Jun 2009, 7:00 AM
DataViews are bound to a store. to add and remove items, you add or remove Records to and from a Store.

Ok, i've found out how to reload the store of the dataView, but not yet how to add new items to it, so that it also keeps the old images that are already in the store.

I currently do it like this:

dataView.store.proxy.conn.url = 'json.php';
dataView.store.reload();

But this ofcourse reloads the dataView with new images, instead of adding it. I know the store has an .add() method, but im not sure how to use... Could you perhaps help me out with thiat..??

vivendi
5 Jun 2009, 9:54 AM
Seriously, noone knows how to add a new item to a dataview that already contains items... WF??

I only know how to reload the store.. Not how to add a new image to it... I seriously can't believe that there's is so little information about this matter... I googled/searched the forum for hours and still can't find any decent solution!

I already have a dataView WITH images. I call another php script that gets a new set of images using the JSonStore method. Now how can i add these new images to the dataView without loosing the images that are already stored in there!?!?


var ble = dataView.store.proxy.conn.url = 'json.php';
dataView.store.reload(); //works BUT discards the images that were already in the dataView! Not what i want!
dataView.store.load(); //does exactly the same as the one above, also NOT what i want!
dataView.store.add(ble); //doesn't work
dataView.store.insert(0, ble); //doesn't work
dataView.loadData(ble); //doesn't work

Maybe you can imagine that this is kinda driving me nuts! Adding new items to a DataView seems to me like one of the things everyone uses!? Yet, noone seems to know an answer for this...

I wonder if it's even possible to add new images to the Store without loosing the old images that are already in there...

5 Jun 2009, 9:57 AM
First and foremost calm down!

This is a volunteer community forum. Want a quicker answer than the volunteers provide? Pay for a subscription.

That said, look at the Editable grid example. It shows how to add new records to the store.

I said this before, and i'm going to say this a second time.
you add or remove Records to and from a Store.

5 Jun 2009, 10:00 AM
Btw, have you seen the Ext 3.0 API?

http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.Store

vivendi
5 Jun 2009, 11:51 AM
Sorry for that.. Just can't believe it's so hard to get it working :(

Anyway, i see that i've to create a new record, and then fill that record with data.

Well, i get the data using a new JSonStore, like so:
(only gets 1 image)


store2 = new Ext.data.JsonStore({
url: 'json.php',
root: 'images',
fields: ['name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date', dateFormat:'timestamp'}]
});


What i get from json.php


{"images":[{"name":"gangster_zack.jpg","size":200,"lastmod":1220048250000,"url":"images\/thumbs\/gangster_zack.jpg"}]}

So now i have to create a record out of this??


var Record = Ext.data.Record.create(store2.fields); //create records out of the newly created store
var record = new Record(store2.component.DefaultValues); //fill the records with the values that are already inside store2 ..? (doesn't work)

dataView.store.add(record);


And about that Edit-Grid example, it uses a hardcoded way to setup a new Record. I use a dynamic way (JSonStore coming from a .php file). So that's why i have a hard time getting this to work, cause it's not entirely the same...

Anyway, i think i'm getting pretty close now... Still hoping anyone that could give me the finishing touch! :(

Animal
5 Jun 2009, 11:55 AM
The Store already has a Record constructor which you can use to create new Records!

http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.Store&member=recordType

vivendi
5 Jun 2009, 12:58 PM
I finally got it working! All i had to do before was change this line:

store.load();

to this line:

store.load({add: true});

So now i have only 2 lines of code in my function!


dataView.store.proxy.conn.url = 'json.php?name='+data2.url;
store.load({add: true});


php file (this is just a testfile!!):


<?php
if(!empty($_GET['name']))
{
$size = 1000;//filesize($dir.$name);
$lastmod = 2000;//filemtime($dir.$name)*1000;
$images[] = array( 'name'=>'gangster_zack.jpg',
'size'=>200,
'lastmod'=>1220048250000,
'url'=>$_GET['name']);
//$d->close();
$o = array('images'=>$images);
echo json_encode($o);
}
?>


PS.
I really don't get why you guys just didn't say something like this... I can't imagine you guys didn't know about this. I think you are 'experts' with extjs, judging by your postcount. This wasn't my first topic about this matter, and all i got was; read the API, look at recordType! look at that example, look at this... etc etc.

When you're new to extjs, you get overwelmed by alot of new functions/methods etc. which are all statically added! I had to add stuff in a dynamic way... As you can see i don't have to re-create records n stuff. Cause it was already there.

Don't get me wrong though, i think you guys are doing a great job here!! I really appreaciate the effort of you guys. I'm just trying to say that sometimes you make it far to difficult for newbies like me.

mjlecomte
5 Jun 2009, 1:55 PM
Several believe in that saying "teach a man to fish...".

MD
5 Jun 2009, 5:01 PM
I really don't get why you guys just didn't say something like this... I can't imagine you guys didn't know about this. I think you are 'experts' with extjs, judging by your postcount. This wasn't my first topic about this matter, and all i got was; read the API, look at recordType! look at that example, look at this... etc etc.

Understand that your explanation of what it was that you were trying to do wasn't very clear. You repeatedly asked how to add to the store. In most cases, this would be done exactly in the way that was described to you, via the store's add() method. If the way it worked out for you works, then that's great. However, adding records via add() is not quite the same thing as appending records via a reload of the store. Which one to use really depends on your specific case. The first reply did in fact give you the correct answer.

As Jay said, this is a volunteer community forum. You can't expect to be spoon-feed, or have people do the learning for you. In most cases, all it takes is a little patience and reading. The API docs cover nearly everything, and when that fails, you can also look directly at the source, and of course the forums. Getting all up in arms because you personally don't understand it, and then blaming others for that -- I think that's seriously unfair to those who were helping you, and disrespectful to this community as a whole.


I'm just trying to say that sometimes you make it far to difficult for newbies like me.

I'm almost speechless in regard to that comment. At first I had a good LOL, then realized you were being serious. /:) There's no conspiracy. No one is intentionally making things difficult for you. As I said -- a little patience and a little reading. You got a perfectly valid answer the first time, but you didn't bother to follow it. If you're looking for someone to blame, there's only one person that fits the bill.

MD

vivendi
6 Jun 2009, 3:18 AM
Understand that your explanation of what it was that you were trying to do wasn't very clear. You repeatedly asked how to add to the store. In most cases, this would be done exactly in the way that was described to you, via the store's add() method.

Are you kidding me!? I seriously LOL'ed at this!
I said i was using a JSonStore to add new images! I wasn't manually constructing a Record so i could use Add() for that. Cause when you check the API docs, all you see is how to manually create a Record, NOT how to make one from a JSonStore. So hopefully you can imagine that someone who just started out with ExtJS get kinda stuck over this....

Also when you check the Add() function in the API docs, you see that it only tells what parameters in needs, now how to use it WITH a JSonStore!

The RecordType function, same thing! It shows how to load a NEW Store! Not how to ADD something to that store!

http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.Store&member=recordType

Later on i was even playing with the Store.load() and Store.reload() functions. I perfectly explained there how and what i was trying to do with the JSonStore. How can that not be clear!?!?!? -_-



As Jay said, this is a volunteer community forum. You can't expect to be spoon-feed, or have people do the learning for you. In most cases, all it takes is a little patience and reading. The API docs cover nearly everything, and when that fails, you can also look directly at the source, and of course the forums. Getting all up in arms because you personally don't understand it, and then blaming others for that -- I think that's seriously unfair to those who were helping you, and disrespectful to this community as a whole.

Yeah i know this is a volunteers community. Like thousands of other forums! But that's not the issue.
And about the spoon-feed, read my first comments about the function in the API docs. Maybe then you understand i wasn't asking to be spoon-feed, but that the API docs just weren't clear enough about my issue. API docs tend to be very general and not problem specific. Don't know if you can imagine that...

And besides, i didn't mean to be disrespectful. I already said that i think they are doing a great job here. But you obviously didn't get my point so i'll try to explain it ultra simple for you.

When someone is VERY good at something, they tend to explain it at their level. So with other words,they say it in a way that seems perfectly logical to them. But not to someone who is new to it. And there's nothing wrong with that, i was just giving my opinion about it, that it's sometimes hard to follow. Something wrong with an opinion!?



There's no conspiracy. No one is intentionally making things difficult for you. As I said -- a little patience and a little reading. You got a perfectly valid answer the first time, but you didn't bother to follow it. If you're looking for someone to blame, there's only one person that fits the bill.

MD

LOL. Who's talking about a conspiracy!? Well hopefully you understand it at this point. If not, i'm not even going to bother about this anymore.

The first answer that i got was:
DataViews are bound to a store. to add and remove items, you add or remove Records to and from a Store.

Looks a bit global to me... Still didn't know what to look for. Add()? Insert()? load()? recordType()? See what i mean...

Animal
6 Jun 2009, 3:26 AM
How about you just look and see what's available?

Browsing the API docs for Store, you'd soon find add, insert, load, recordType!

And then reading the docs on those, I'm sure you'd understand them. And then off you'd go!

Animal
6 Jun 2009, 3:28 AM
Or... hmmmm...

Are you one of the people who thinks that the entire documentation effort for Store.load amounts to



Loads the Record cache from the configured proxy using the configured reader. If using remote paging, then the first ...


?

mjlecomte
6 Jun 2009, 5:35 AM
If anyone thinks the API Docs can be improved in some way please make specific constructive suggestions so someone can try to improve them.

I'm not sure where you looked in the API before you found your answer. I'm also not sure if you actually found the answer spelled out in the docs or not.

mjlecomte
6 Jun 2009, 5:41 AM
when you check the API docs, all you see is how to manually create a Record, NOT how to make one from a JSonStore.

...

The RecordType function, same thing! It shows how to load a NEW Store! Not how to ADD something to that store!

http://extjs.com/deploy/ext-3.0-rc2/docs/?class=Ext.data.Store&member=recordType



You found the RecordType property, as you have linked. There is an example there showing how to add a record to the store. Please clarify your position so the docs can be improved if needed.

mjlecomte
6 Jun 2009, 5:50 AM
Re-reading over this thread it looks like all constructive suggestions were valid. What appears to be of confusion is that there are a few ways to skin a rat.

So you can add a record using store.add() or store.insert() as the recordType property example illustrates.

Or you could use load() and specify add:true.

cripkd
10 Aug 2009, 1:16 AM
I'm going to be offtopic here, but here it goes.
I've been playing around with extjs for a few months now, just fell in love again with it, after v3 came out.
I fnially got around to understanding some of the stuff that was unclear, learned to dig deep into the examples in the demo section and in the API. I don;t mind digging in api's and getting my feet wet.

I also think the guy was disrespectful and arogant and/or whinny.
I too have asked questions in this forum, didn;t get any answers, continued digging, got it solved and was happy about it. Case closed.

BUT. I think there is a big "but" here. I've actually thought about this stuff (having read/skimmed over hundreds of project apis) and I came to the conclusion that basically there are 2 ways for writting docs. Project oriented, like ExtJS mainly has, where you go over every little method and parameter and so on, and developer (or solution) oriented, where you go over "recipies", how to solve common problems.

Yes, i know the api docs are _API_ docs so there is a point why they just list stuff (and they do a great job I guess, from the nice interface to the way they are linked and so on) and I also know that from place to place you actually find nice examples, so more like developer/solution oriented, if you know where and how to look for them.
Like for example the TreePanel section, where you see examples of using a dynamic tree.

But maybe because of the interface, with all "expand buttons" closed or something, its actually hard to find the more advanced examples.
Also, in the same TreePanel region, i find it hard to actually understand how to best chose one of the 2 options, what exactly the difference is, when to use a dataUrl option and when to use the children option of the root item and why the json looks different in the 2 cases (or how hierarchy is created using the first example). I could give more examples of how and why i found the docs annoying at times, if only i was an ExtJS master or if telepathy existed :)

Otherwise, thanks for all the great work, I really like ExtJS :)

Animal
10 Aug 2009, 1:44 AM
I kind of agree.

The trouble with recipes is that there is so much flexibility, that they won't work everywhere.

If you look at a lot of the code samples in the API docs (and tere are a lot now, and increasing), you will see that they illustrate just the call being documented.

The example code will probably be a very bad way of diong things in a proper, OO application.

But people create "cargo cult" applications by pulling in strange incantations from wherever they can which they do not underastand.

And then they get in trouble because they've created a tottering heap that they have no understanding of, and come here and complain.

My constant point is that a far far better thing to do is to understand the underlying principles of the library.

One key principle which must be grasped almostbefore youdo ANYTHING is:

The Container->Component hierarchy in which a Container's layout is responsible for rendering and sizing the contained child Components.

cripkd
10 Aug 2009, 3:15 AM
I agree on the container stuff, though i haven't totally grasped it (and BTW, how can i do that? what is there to read, to understand, and where?) i started to, and learned to keep layouts as simple as possible so that all sizing can be handled by the containers by themselves.

But what I lack understanding (or more to the point, experience) in is application architecture. I can understand most of the OOP stuff going on in the examples in the demo section, but I can't think like that, I can;t come up with a solution on my own when i ask my self: ok, how should i do this?

Also, shouldn't there be like a class structure/flow of ExtJS , just so everyone can understand that for example for a DataView you need a Store, consisting of a Loader and a Reader (i might be totally aberant here :) ) and those can be of different types?
Then, how exactly do you plugin stuff like Drag and drop accross different components?
For example the ddGroup option comes in handy, but you never hear of it unless you dig trough the examples. You can't be expected to read the whole API and then start coding, right? :)

Anyway, I know that things can always be better and i know that my view is very subjective and that even if I was 100% right, people would still need to sacrifice their time to provide me with all this info i seem to be needing and thats why I don;t actually pretend to have the absolute truth. I'm just mentioning these things because someone in the thread said that if anyone has some suggestions about what the docs are missing they should point things out.

mjlecomte
10 Aug 2009, 3:28 AM
I agree. I think current practice has left room for people to write books about the subject....and those now exist.

I don't detect an actual suggestion in your posts, if you have one. One standing gripe has been there's so much information on this site, but it's scattered.

Animal
10 Aug 2009, 3:38 AM
I agree on the container stuff, though i haven't totally grasped it (and BTW, how can i do that? what is there to read, to understand, and where?) i started to, and learned to keep layouts as simple as possible so that all sizing can be handled by the containers by themselves.


I keep adding stuff in the good old fashioned, neglected docs: http://extjs.com/deploy/dev/docs/?class=Ext.Container

Truly, all Ext-based wisdom is there.

You could also use

http://extjs.com/learn/Tutorial:Creating_new_UI_controls


But what I lack understanding (or more to the point, experience) in is application architecture. I can understand most of the OOP stuff going on in the examples in the demo section, but I can't think like that, I can;t come up with a solution on my own when i ask my self: ok, how should i do this?


Same boat as me. All I can say is don't blindly use the first thing you find. It's likely to be a millstone rather than a lifeboat.

Experiment, learn the principles, and then come up with your own design based on what you know, and a little of what's already out there.


Also, shouldn't there be like a class structure/flow of ExtJS , just so everyone can understand that for example for a DataView you need a Store, consisting of a Loader and a Reader (i might be totally aberant here :) ) and those can be of different types?


Someone has done an inheritence diagram. (But each class has its own at the top right of its API page)

DataView, and other data-driven widgets need a Store because they are data-driven. There's no rule there. It's just a configuration option.


Then, how exactly do you plugin stuff like Drag and drop accross different components?
For example the ddGroup option comes in handy, but you never hear of it unless you dig trough the examples. You can't be expected to read the whole API and then start coding, right? :)


DnD is a topic all in itself. It's very complex. Did youi see the examples in your examples directory. One of them (written by me) is extensively commented.

Jay Garcia is covering it in his book.


Anyway, I know that things can always be better and i know that my view is very subjective and that even if I was 100% right, people would still need to sacrifice their time to provide me with all this info i seem to be needing and thats why I don;t actually pretend to have the absolute truth. I'm just mentioning these things because someone in the thread said that if anyone has some suggestions about what the docs are missing they should point things out.

As MJ said. Feel free to suggest contributions and additions.

The documentation is added to every single day in response to questions and misunderstandings here.

BTW, you DO know that every segment in a class's API page expands to a full description don't you?

cripkd
10 Aug 2009, 3:50 AM
I keep adding stuff in the good old fashioned, neglected docs: http://extjs.com/deploy/dev/docs/?class=Ext.Container (http://extjs.com/forum/../deploy/dev/docs/?class=Ext.Container)

Truly, all Ext-based wisdom is there.

You could also use

http://extjs.com/learn/Tutorial:Crea...ew_UI_controls (http://extjs.com/forum/../learn/Tutorial:Creating_new_UI_controls)
Very nice, I'll start reading, thanks :)


DnD is a topic all in itself. It's very complex. Did youi see the examples in your examples directory. One of them (written by me) is extensively commented.
Great, which one?

As MJ said. Feel free to suggest contributions and additions.

The documentation is added to every single day in response to questions and misunderstandings here.
Well, I wasn't saying that I actually HAVE some additions/corrections to make. I said i was trying to be as to the point as possible when complaining about the current state of the docs, that's all, and I knew from the start that because I'm new to this I'm either no right or not able to point exact stuff out :)


BTW, you DO know that every segment in a class's API page expands to a full description don't you?
Hahah, yeah, I know. I also said that maybe that prevents me and other people to see where some of the examples are hidden (some are in the constructors, but some are in some other config option and/or property). Maybe more important areas in an api doc page should be expanded by default? Don't know, just an idea. Or an expand all button? If there already is one, please shoot me, i tend to not see stuff in front of me.

cripkd
10 Aug 2009, 3:53 AM
Or an expand all button? If there already is one, please shoot me, i tend to not see stuff in front of me.
Consider me shot :)
I just found it, Expand all members. And as an example of what I was saying, i just hit that on the GridPanel and just saw some of the stuff in the bodyCfg i had no idea of.
Yes, i guess you were right, there;s too much stuff in the docs, too many (very usefull options). Count me with that crowd that "complains" about that then :)

Animal
10 Aug 2009, 3:55 AM
There is an expand all buton!

Right next to the "hide inherited members" button which is also nice if you are overwhelmed.

My example is the dragdropzones.html one. dblclick that, and there's a "View Source" button which shows you the code with full explanations of what each bit is diong.