PDA

View Full Version : Delete Item from simpleStore



JFB
29 Jun 2010, 3:53 AM
Hello,
I'm trying to delete an item from simpleStore without success.
I try this:
myStore.loadData(myData);
myStore.remove(0); //where 0 in my first item index
myStore.commitChanges();

Any ideas why is not working?
After that I'm assigning mystore to a comboBox.
Thanks in advance.

Johnny

yyogev
29 Jun 2010, 4:20 AM
Hi,

I think you can skip the commitChanges(), but in order for the view to display the change add this:
myStore.fireEvent("datachanged", myStore);

JFB
29 Jun 2010, 4:51 AM
Thanks for you reply and help.
It's not working...
I declare myStore like:
var myStore = new Ext.data.SimpleStore({
id: 0,
fields: [{
name: 'id',
type: 'string'
}, {
name: 'text',
type: 'string'
}]
})
Do I need anything else?
Rgds

Johnny

yyogev
29 Jun 2010, 5:07 AM
What does your data look like ?
a sample data should like:

var data_array = [ ["id1", "text1"], ["id2", "text2"]];

BTW, if you only use strings, you can define fields like

fields: ['id', 'text']

(use CODE tags around your code - '#' button in reply toolbar)

JFB
29 Jun 2010, 5:17 AM
Yes, my data looks like your example.
Got it, I change my store declare as your code.
It's not working. I can see the 0 index data when I display the store in firebug.
I'm new in extJS, this is running my crazy, thanks for your help!
Rgds

Johnny

JFB
29 Jun 2010, 5:44 AM
I try this as sample and still showing text1 and test2
Any other ideas?


var data_array = [ ["id1", "text1"], ["id2", "text2"]];
var myStore = new Ext.data.SimpleStore({
id: 0,
fields: ['id', 'text']
})

myStore.loadData(data_array);

myStore.remove(0);
myStore.fireEvent("datachanged", myStore);
console.log(yearStore);

yyogev
29 Jun 2010, 6:22 AM
This sounds strange. Usually you load a set of records, and later delete one when you need to (user deleted or for some other reason).

JFB
29 Jun 2010, 7:33 AM
Because in one comboBox I want to display the first item that is ["","Select Item"] and in another ComboBox I would like to take that away and display the first item of my data.
I want to skip a database call for build another comboBox if I already have the data.
Can I do something in the comboBox?
Like to skip the 0 item or maybe not to display the 0 item.
Thanks!

Johnny

evant
29 Jun 2010, 7:47 AM
Look at the docs for remove, it requires a record object:



store.remove(store.getAt(0));


In 3.x, there's a removeAt method.

JFB
29 Jun 2010, 8:21 AM
You got it man... Thanks!
estJs documentation should have samples.

Johnny

yyogev
29 Jun 2010, 9:58 AM
Because in one comboBox I want to display the first item that is ["","Select Item"] and in another ComboBox I would like to take that away and display the first item of my data.
I want to skip a database call for build another comboBox if I already have the data.
Can I do something in the comboBox?
Like to skip the 0 item or maybe not to display the 0 item.


I'm not sure I understand the desired behavior in your application.
If you have two different combos you should use 2 separate stores.
I think the correct way to do this would be either:


take the source array array1, copy item 0 to array2, then use array1 with store1 in combo1, array2 with store2 in combo2.
If filtering in combo2 is done by value in combo1: copy array1 to array2, use array1 with store1 in combo1, array2 with store2 in combo2, and apply filter to store2 when selection changes in combo1.

zhuangyinqian
30 Jun 2010, 12:12 AM
This is the function that you want to remove the certain record

function(store,index){
store.remove(store.getAt(index));
}