How can I Change the cellClass on columnResized? - ag-grid-react

How can I Change the cellClass in onColumnResized function?
Example: when the size of the column increases or decreases cellClass should be change accordingly.

Declare a global Boolean variable
Initialize it to false
Now write a function for onColumnResized
Set the variable as !(variable_name). So, in this way first time on column resize this variable will be set to true and next time it will be set to false.
Now use cellClassRules instead of cellClass and write a function where you check whether this variable is true or false using a ternary condition. If true apply one class, if false apply another class.
Mention the styles for those classes in css file.
PS: The reason why I have asked you to use cellClassRules instead of cellClass is:
cellClass: All new classes are applied. Old classes are not removed so be aware that classes will accumulate. If you want to remove old classes, then use cellClassRules.
cellClassRules: Rules that return true will have the class applied the second time. Rules tha return false will have the class removed second time.

Related

Binding boolean (Property) to List operations in JavaFX

I found JavaFX to be suprisingly expressive after getting over the fact that I had to redeclare every field as property so I am a little stumped and would like to know if there is a better, more idomatic way of binding a boolean to some more complex operation like adding and removing style classes.
In this example I have a project that maybe valid or not and I want the font color of the tab to indicate which it is. I am doing this by adding and removing the error style class:
val errorSwitch = { valid : Boolean ->
logger.debug {"errorSwitcher: $valid"}
if( valid) tab.styleClass.remove("error")
else tab.styleClass.add("error")
Unit
}
product.isValid.onChange (errorSwitch)
errorSwitch(product.isValid.value)
What I don't like here is that I have to call the function once myself to start with because "onChange" obviously does not trigger unless the isValid actually changes. It's a small thing but I am wondering if there isn't a better way with bindings because thats what I want: the presence of the error class should be bound to "isValid"
In TornadoFX the best way to achieve this is to use the toggleClass function, which will automatically add or remove a given class based on a boolean observable value. Therefore you can simply say:
tab.toggleClass(Styles.error, product.isValid)
This example requires you to use the Type Safe CSS feature of TornadoFX. Read more about Type Safe CSS in the guide :)

Can one constraint on a command object check the result of another?

This is a simple example that doesn't work, I'm wondering if there is a way to validate a inside the validator block of b if it hasn't already been validated.
Example how I thought it would work:
static constraints =
{
a nullable: false
b validator: { val, obj ->
if(obj.errors.hasFieldError('a'))
{
return false
}
}
}
Note: in this scenario obj.errors.hasFieldError('a') returns false even if a is null.
I don't think there's any guarantee of the order the constraints are checked, and it's unlikely that it would have anything to do with the order specified in the constraints block.
However, in addition to the common one-arg custom validator that passes you the current value for that field and the two-arg validator you show where you also get access to the domain class instance, there's a three-arg variant (unfortunately it doesn't seem to be covered in the Grails reference docs ...) where the third argument is the Spring Errors instance. If you define a three-arg validator, GORM ignores any return value since it's assumed that you'll be working directly with the Errors instance, calling one or more of the different rejectValue methods yourself for any validation issues.
So you could remove from the constraints block any standard validations that you want to run yourself and use this approach instead. You can find more information about working with the Errors object in the Spring docs.

Assign value to Swift property

When should I assign value to properties in swift?
What is the difference between
class Thing {
var something:String = "Cool Thing"
}
and this
class Thing {
var something:String
init(){
something = "Cool Thing"
}
}
Actually its quite obvious when value is assigned on init() but when is value assigned when using 1st piece of code and which is the right way to do?
They're the same, but Apple suggests using the default property value pattern "if a property always takes the same initial value" for stylistic reasons. See the note in Default Property Values section of The Swift Programming Language: Initialization, which says:
Default Property Values
You can set the initial value of a stored property from within an initializer, as shown above. Alternatively, specify a default property value as part of the property’s declaration. You specify a default property value by assigning an initial value to the property when it is defined.
NOTE: If a property always takes the same initial value, provide a default value rather than setting a value within an initializer. The end result is the same, but the default value ties the property’s initialization more closely to its declaration. It makes for shorter, clearer initializers and enables you to infer the type of the property from its default value. The default value also makes it easier for you to take advantage of default initializers and initializer inheritance, as described later in this chapter.
You can use any of the 2. The difference is that if you have multiple initializer you might need to replicate the property initialization. Besides that it's just a matter of preference.
They should both be doing the same thing. The main difference for not initializing first would be if you wanted to assign the var as an optional and test for nil. Otherwise assigning the value would be the same.
var something:String?

How to define a Result class which can be treated as boolean but has methods

I'm working on adding further feature for a authentication module, for some reason, I cant change the interface, so the result should be used in some if..else condition.
I think I may need to define a Result class and return it's instance as result, this result can be treated as boolean so that the original projects which using this method will not be influenced and I can get the further info by calling method (for example: the reason of why validate is false). I think the following way can match my goal by return true or false.define_method(:reason, proc[]{return reason}) but I think it's not a best way to do it.
Any idea is good idea, thanks
Only false and nil are false values in Ruby, instance of your result class will definitely be true.
true and false are unique in Ruby. They are the only instance of TrueClass and FalseClass, respectively. Defining singleton methods on them will affect all other places using true or false. This may work in single threaded programs, but possibly not for multi threaded programs.
If the authentication API that you cannot change accepts only boolean values, I don't think you have good way to add further features while keeping backwards compatibility.

How do I access the Activerecord setter I overrode?

I want to use a custom setter to do some formatting of my fields. In irb if I test the setter like:
o.field_name = "4"
I see that my custom setter is being referred to. But with this it is not:
o[:field_name] = "4"
I understand that in the first case this is a function call and in the second case we are just setting the attribute directly. But I don't completely see how the attribute can be set without going through our custom setter, I thought that was the point.
But my main question is that if var holds my field_name, I don't see how to dynamically refer to a.var and have it be interpreted as a.field_name. All I see to do is a[var] and this bypasses my setter.
Try a.send(var) where var = 'field_name'
That's the equivalent of a.field_name
o[:field_name] is like read_attribute(:field_name), thus is just reads the value as you said. It can be quite important in virtual attributes in order to bypass the stack too deep error. If you do a[:var], you just get its value. A virtual attribute refers to an attribute, if you are setting its value to another variable, you just get its value, not the object.

Resources