Ag Grid getModel - filter

I have a React project with rowModelType = 'serverSide'.
I also have a custom component for filtering.
And I have an external button that should clear this filter
When I click on the button the function is triggered - gridApi.setFilterModel(null);
Next, the setModel function is called in the component
Where
assigned to this.setState({checkedFilters: []})
Next, the gridApi.getFilterModel() method is called;
Next, the getModel() method is called where this.state.checkedFilters is equal to the old value i.e. [1,2]
Maybe somebody will prompt in what a problem of obtaining of old value?
**Component state =
this.state = {
checkedFilters: [1,2]
};**

Related

Access the child (Button) of a prefab and add function OnClick to it. Unity

I have a prefab which contains some buttons and I want to get the buttons and add specific onClick functions to them via script. I cant find the right way to get the buttons.
What I am trying is:
tempGo = Instantiate(prefabs[0]);
tempGo.transform.SetParent(transform, false);
tempGo.transform.localScale = Vector3.one;
tempGo.transform.localPosition = Vector3.zero;
Transform t = tempGo.GetComponentInChildren<Transform>().Find("AddGoals");
"AddGoals" Is my Buttons(Tag name)
So after this point how can I code it to add a specific function when the button gets clicked?
Any help would be appreciated thank you!
Get button component and add listener to it. Listener will call the function when that button is clicked. TaskOnClick is an example function that will be called when the button is clicked.
t.GetComponent<Button>().onClick.AddListener(TaskOnClick);
void TaskOnClick()
{
Debug.Log("You have clicked the button!");
}
Using .Find(""), you are looking for a gameobject with that name, not its tag. What you can do is after instantiating the object, use GameObject.FindGameObjectsWithTag("AddGoals"). This will return an array of all of the objects with that tag. Then with Linq you can do something like:
var items = GameObject.FindGameObjectsWithTag("AddGoals"); //This gives gameobject array
var itemTansforms = items.Select(x=>x.transfrom).ToList(); //gives you a list of the object tansforms
As for adding an event, you would need to grab the button component of the object and then add the onclick event.
items.ForEach(x=>x.GetComponent<Button>().AddListener(delegate {Debug.Log($"{x.name} has been clicked")}));
You would have to make sure it is actually a button, or the code will fail. This of course can be modified and is just an example. I hope this helps!

ExtJS: Clear a data binding from a viewController

I am using the admin-dashboard template and made the following modification to the MainController:
routes: {
':node': {
before : 'checkSession',
action : 'onRouteChange'
}
},
Thus, when I change a route the before route will happen first, so the following method will first get called and then the routing will proceed onward:
checkSession : function() {
var args = Ext.Array.slice(arguments),
action = args[args.length - 1],
hash = window.location.hash;
// TODO: use hash to clear patient header when appropriate
if (hash.indexOf('#new-patient') > -1) {
console.log(hash);
}
action.resume();
},
This works splendidly. However, when I get the condition of hash.indexOf('#new-patient') > -1 I would like to clear a comboBox that I have defined in a view as:
bind: {
store: '{patients}'
},
reference: 'patientCombo',
This is from a view in the same scope as the above method from the viewController is, that is they are both in the hierarchy of the same viewModel. I am just not sure exactly how I can clear this from the above method. I just want to set the combo box back to no selected value (if one had been selected) and then update the bindings. Merci!
When I tried using Ext.ComponentQuery, I initially referenced the itemId, but the xtype was wrong (the combobox and displaytext, among other sundries are in a container). Since this is the only combobox in my app now, I just tried it as:
combo = Ext.ComponentQuery.query('combobox')[0]
if (combo){
combo.setValue('')
}
and, lo' and behold, it worked!

Angular2 - DOM events lost on re-render when using Redux and uni-directional data flow

I wasn't sure of the best way to word the title, but hopefully the description will clarify.
I have an Angular2 component that uses Redux for state management.
That component uses *ngFor to render an array of small inputs with buttons like this. The "state" is something like this...
// glossing over how I'd get this from the Redux store,
// but assume we have an Immutable.js List of values, like this...
let items = Immutable.fromJS([{value: foo}, {value: bar}, /*...etc*/ })
And the template renders that like so...
<input *ngFor="let item of items, let i = index"
type="text"
value="item.get('value')"
(blur)="onBlur($event, i)">
<button (click)="onClick($event)">Add New Input</button>
When an input is focused and edited, then focus is moved away, the onBlur($event) callback is called, a redux action (ie: "UPDATE_VALUE") is dispatched with the new value.
onBlur($event, index) {
let newValue = $event.target.value;
this.ngRedux.dispatch({
type: "UPDATE_VALUE",
value: {index, newValue}
});
}
And the reducer updates the value (using Immutable.js):
case "UPDATE_VALUE": {
let index = getIndex(action.value.index); // <-- just a helper function to get the index of the current value.
return state.updateIn(["values", index], value => action.value.newValue);
}
The state is updated, so the component is re-rendered with the updated value.
When the button next to the input is clicked, the onClick($event) callback is fired which dispatches a different redux action (ie: "ADD_VALUE"), updates the state, and the component is re-rendered with a new blank input & button.
The problem comes up when the input is focused (editing) and the user clicks the button. The user intended to click the button, but because they happened to be focused on the field, it doesn't behave as expected. The (blur) event is fired first, so the input onBlur callback is fired, redux action dispatched, state updated, component re-rendered. BUT, the button (click) is lost, so the new input isn't created.
Question:
Is there a way to keep track of the click event and trigger the second action after the re-render? Or, is there a way to somehow chain the redux actions so they happen in sequence before the re-render?
Side-note - I've tried changing the (click) event to use (mousedown) which is triggered before the (blur) but that caused Angular (in devMode) to complain that the #inputs to the components were changed after being checked (the state changed during the change detection cycle). I didn't dig into that too deeply yet though. I'm hoping to find a solution using click and blur as is.
Thanks!

need to get value of dropdown menu without using onChange callback - (material-ui reactjs)

i am using material UI dropdown component and trying to run a callback function only when user fills all the form and submits the form. On the call back function i intend to collect all the form field and generate url to call to api.
My problem is that i can not use onChange as stated solution in #560 as i want to collect all the detail only when user clicks the submit button. It is also weird that at the moment, i am able to get value of all the other form element like slider, textfield which uses material-ui but only dropdown does not seem to be working.
My call back function:
handleFilter: function(event){
event.preventDefault();
var location = this.refs.location.getValue();
var posted_date = this.refs.posted_date.getValue();
var radius = this.refs.distance.getValue();
var salary = this.refs.salary.getValue();
var jobtype = this.refs.jobtype.getValue();
console.log(jobtype);
}
In the above function "location, posted_date, radius, salary" returns value but "jobtype" which happens to be dropdown does not seem to return any value. It returns this error in console:
"Uncaught TypeError: this.refs.jobtype.getValue is not a function"
Here is my dropdown component :
<DropDownMenu menuItems={menuItems} ref="jobtype" />
May not be the right way but i figured out that
console.log(this.refs.jobtype) (jobtype is the refs value of dropdown in my case)
was giving the following result.
R…s.c…s.Constructor {props: Object, context: Object, state: Object, refs: Object, _reactInternalInstance: ReactCompositeComponentWrapper}
Inpecting it i found value of payload index (index number of selected item) inside state object within "selectedIndex" property. I used following code to access the selected index:
var jobtype = this.refs.jobtype.state.selectedIndex;
If there is a better way to do this please suggest.

Kendo TreeView select function and event misbehaviour

For the ones who might spend hours trying to understand why they don't get the same behaviour from the select callback whether it is triggered by the select event or by the select method.
I couldn't understand why this was working perfectly when I picked an item manually, while there was no reaction if I was using the method. I have tried to trigger the event on the tree element, on the widget itself as it seemed it was not triggered at all.
select: function(e){
var item = e.node;
appui.f.post("admin/object_editor/obj/" +
( typeof(item.class) !== "undefined" ? "object" : "field" ) +
"/" + item.id + "/" + item.uid, {partial:1}, $("#object_cfg_container"));
}
The function is triggered but returns an error from the first line when the select method is used.
Actually what happens is that the event is sent as the function's argument, in which you can find the node property, which is the newly selected object.
However when you use the select method the event argument doesn't have anymore the node property.
So maybe you found out that the select() method used without arguments returns the selected element.
But a new problem appears, this function will return the old selected item when launched during the event, while it will return the newly selected item if it's launched as a method...
My solution:
select: function(e){
var item = e.node ? e.node : this.select(),
data = this.dataItem(item);
....
}

Resources