I have a treestore in which all nodes have the initial config checked:false , so that a checkbox will appear, allowing the user to check items in the treepanel. I then get the checked items from the treestore and move them to another treestore, in another tree panel. My question is how do I, when moving the node, make sure it is not checked in the treepanel it is moved to?
Here's what I have done:
I have gotten a reference to the node I am moving(adding to one store, removing from the other), and I have set it's config checked:false. When I view the node in firebug after it is within the new treestore, sure enough, checked:false, which is what I wanted, however, within the panel, visually, it is still checked. So How do I make it uncheck??
There are a couple of reasons why this could be happening.
The dataIndex of the new column does not match the dataIndex of the old column(in the case of using a treegrid)
Your model assigned to both stores is not the same Ext.data.Model in both cases.
I have noticed some weirdness with treenodes and attributes not working if you don't specifically add that config option to your Ext.data.Model. So try assigning the same model to both trees with "checked" as one of the fields with dataType: "boolean"
I had the same problem last week.
I made this kind of operations last week to solve it:
currentNode.data.checked = false;
currentNode.raw.checked = false ;
currentNode.triggerUIUpdate();
It seems it didn't work without the triggerUIUpdate. I am working with extjs4.2.1
Related
I reconfigure my store and add new fields to it and then load its corresponding grid. I need to edit grid cells and save the whole modified grid rows in one step at the end.
The problem is that when I call this code, I get all rows in the grid even if I haven't edited any cell or row in the grid maybe because I have reconfigured the store.
But in fact nothing has been changed and new fields in the store are just for view.
How can I get the rows which their cell values has been changed ?
// returns all store records
Ext.ComponentQuery.query("documentgrid")[0].getStore().getModifiedRecords();
Your issue is not described quite clearly.
With a little guess,give you this answer,I hope it would help.
The getModifiedRecords() is not for that use.
Subscribe the store's "update" event instead.It can hook into the modification of model fields in the store.
Try code snippets:
{
//your grid config goes here
listeners:{
update:function(me, record){
//TODO save the modified record somewhere for your save button to pickup.
}
}
}
I was getting all the records because I hadn't call commitChanges on the store after reconfigurer.
i have a list bound to a data store. when i remove a record from that store i get an error at
dom.parentNode.removeChild(dom);
Ext.define.afterRemove (ext-all-debug.js:23908)
Ext.define.removeDocked (ext-all-debug.js:33183)
Ext.define.hideVerticalScroller (ext-all-debug.js:77741)
Ext.define.determineScrollbars (ext-all-debug.js:77651)
Ext.define.onViewRefresh (ext-all-debug.js:77869)
call (ext-all-debug.js:10472)
because dom.parentNode is null. the dom object is a gridscroller and the event seems to be happening as some standard delayed layout refresh.
basically, this happens after i delete a record from a store that is bound to a list.
store.remove(rec);
store.sync();
am i doing something wrong?
well, it looks like it was a bug in version 4.0.7 because 4.1 works.
Is there a way to suppress model validation in Backbone.js when a new model is first created?
In my app, I have a collection with an arbitrary number of models, which are represented as list items. The user can click a button on each item, which inserts a new empty item beneath the current item. The empty item is failing validation, obviously, because I don't want an empty item being saved later.
There's no way for me to know what sensible defaults might be when I'm creating the new item, so prepopulating the new model with valid data doesn't seem like an option.
Any suggestions?
Update: While working on a tangentially related problem, I realized that I was using Backbone.js version 0.9.0. When this version was released, other people had the same problem I was having, and they complained in this issue on GitHub.
Jeremy modified validation in 0.9.1 to fix this. Adding a (temporarily) empty model to a collection is a valid real-world usecase. You could handle the new, empty model in the view, but if you're managing a list of items like I am, that forces you to have a collection of item views (including the empty one) in addition to your collection of must-be-valid models. That's a really clunky workaround for an otherwise straightforward scenario. Glad this got fixed.
You're not supposed to add invalid models :)
Digging a bit in Backbone source code (0.9.1 at least) showed that the mechanism can be circumvented by passing options to your add method:
var Mod=Backbone.Model.extend({
validate: function(attrs,opts) {
if (opts.init) return;
return "invalid";
}
});
var Col=Backbone.Collection.extend({
model:Mod
});
var c=new Col();
c.add({},{init:true});
console.log(c.length);
A Fiddle: http://jsfiddle.net/jZeYB/
Warning : it may break things down the line.
Do you need to add the model to the collection right away? I presume that validation fails because you add it to the collection immediately.
Instead, when the button is pressed you could just create the view and blank model. When the model validates you add it to the collection. You would need a submit button/mechanism on the new row to add it to the collection (which invokes validation automatically).
I have a button that when clicked, will create a JSONstore using a url provided. The store is then loaded into a grid. If the button is clicked again, it adds all the information again (so it is listed twice). I want it so that when the user clicks the button, it clears the store/grid and then adds everything.
Any ideas on how to accomplish this?
Thanks,
EDIT
ExtJS 3
datasetStore.removeAll();
datasetStore.loadData(datasetsArray);
It will be useful to see some code examples (and extjs version), but you can simply use loadRecords method (http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.JsonStore-method-loadRecords):
grid.store.loadRecords([array of your new records here], {addRecords: false});
{addRecords: false} indicates that existing records will be removed first.
for ExtJs4: simply doe store.loadRecords([ array ]). In version 4.2.2 the store.proxy has NO clear() method so that doesn't work (was proposed in other examples elsewhere...)
If you want to to totally clear store and proxy, pass an empty array. This is handy because in some cases you want to clear the store and removeAll only moves the data to an array managed internally in the store so when later doing a sync on a gridStore which shows only 1 record, you may see your controller flooded with a bunch of records marked for removal!!
I have a combo field with queryMode: 'remote' and the store has a structure similar to this:
{
success: true,
data: [
{'name':'john','value':1},
{'name':'mary','value':2}
]
}
How can I remove the first element of the data array if I want to, before it is loaded into the combo list?
I tried capturing the load event and splicing the data array but I didn't seem successful.
A solution in the context of the one posted in this thread would really be helpful.
First of all, removing the first element in the UI is questionable, if you ever decide to expose your services through web services, that logic of removing the first element won't be there.
That being said I think you can listen to the load event and do store.removeAt(0)
override getData of reader in store.