I want my renderer to run only once for each row.
So obviously my renderer should look something like
renderer: function() {
if (there_is_a_rendered_value_in_view) {
return rendered_value_in_view;
}
return 'generate some return';
}
Is it possible to do?
So how to get rendered_value_in_view?
UPD:
seems like I'm not detailed enough.
Well, the generated value after that is changed outside the grid, so the question is: How to get currently displayed value
You can always add boolean flag, and your rendered_value_in_view to the grid itself. And then in the renderer function check grid property and return it.
Update: from the Sencha docs here are list of parameters your renderer function will get:
value : Object
metaData : Object
record : Ext.data.Model
rowIndex : Number
colIndex : Number
store : Ext.data.Store
view : Ext.view.View
I think the last one will be your grid object.
http://docs.sencha.com/ext-js/4-0/#!/api/Ext.grid.column.Column-cfg-renderer
It'd be fairly difficult to try and capture the rendered value. I think the better way would be to add another model to your field that contains this new value. You can use a convert method so that when the original value changes, the display value can also change.
Maybe -
...
there_is_a_rendered_value_in_view:false,
renderer:function() {
if (!this.there_is_a_rendered_value_in_view) {
this.there_is_a_rendered_value_in_view=true;
return rendered_value_in_view;
}
return 'generate some return';
}
Related
I have the following Table,As you can see one Name can have multiple values, which are displayed as a block. I want for it looks like this: if a Name has multiple Values, the Values should be displayed inline.
View-part: Is done in XML, with the access to a Model data. In this case:
model>Name and model>Value. The data in the Model is represented the way it is in the Table.
I do not want to change the way data is being displayed in the Model, however, I would like for the View-part to look different.
What I tried: Wanted to change the way Data is being displayed in the Model but realized, the Data within the Model is being used for different circumstances those changing it could cause more Problems
How do I introduce some logic into XML or Another way to display the data how iI want for it to be displayed?
If you are using the responsive table (sap.m), the columns have a "merge duplicates" property. Here is an example:
Merged Cells Table
I think you are looking for this (conditional binding).
new Text({"visible" : "{= ${status} === 'critical' && ${amount} > 10000 }"});
This can be used for simple checks (booleans, length of array, value bigger or small, etc).
If you need more advanced logic on you bindings you should use formatters, look here.
// In view
<ObjectStatus text="{path: 'invoice>Status', formatter: '.formatter.statusText' }"/>
// In formatter
statusText: function (sStatus) {
var resourceBundle = this.getView().getModel("i18n").getResourceBundle();
switch (sStatus) {
case "A":
return resourceBundle.getText("invoiceStatusA");
case "B":
return resourceBundle.getText("invoiceStatusB");
case "C":
return resourceBundle.getText("invoiceStatusC");
default:
return sStatus;
}
}
I have an example here:
http://www.search-this.com/examples/angular-help/
If you double-click "Text Message" in the list it brings up an input box.
type "one" in the input box and click the update button.
Notice the console.log
click SmsResponseActionParmAndValue to expand and locate the "Text Message" option
click ParmAndValue to expand and notice the Value property has our "one" value we typed in.
Now type two in the input box and look at the console.log and notice it doesn't update? It only updates the first time?
Help please...
which is getting updated in selected object not in main JSON object.
$scope.updateDetails = function () {
console.log("update");
console.log($scope.actions); //
console.log($scope.selectedAction); // look in this object updated you have to override it to original object or use 2 times ng-repeat to bind.
};
This is very ugly i know but its a solution:
$scope.updateDetails = function() {
angular.forEach($scope.actions.SmsResponseActionParmAndValue,function(action){
if(action.Description === $scope.selectedAction.Description){
console.log($scope.selectedAction)
action.ParmAndValue = $scope.selectedAction.ParmAndValue
return;
}
});
console.log($scope.actions)
};
The problem is that the updated model doesn't point to the same array in memory as the original object so we have to update the array that the original object points to.
In ExtJS panel I need to set value of all items (e.g. textfield, pathfield) to blank. I don't want to set value of each individual item to blank but of whole panel in one go.
I am able to get list of items
function getAllChildren (panel) {
/*Get children of passed panel or an empty array if it doesn't have thems.*/
var children = panel.items ? panel.items.items : [];
/*For each child get their children and concatenate to result.*/
CQ.Ext.each(children, function (child) {
children = children.concat(getAllChildren(child));
});
return children;
}
but how to set to blank for whole panel? Please suggest what need to be done in this case.
Actually, it's not possible to do it with one liner - all at the same time. What your method returns is purely an array of objects. In fact if such syntax existed, it would iterate over all fields anyway.
Though clearing all fields, having the method you've proposed is very trivial to do. Just iterate over them all and call reset method. Mind some (especially custom) widgets might not handle it.
var fields = getAllChildren(panel);
CQ.Ext.each(fields, function(field) {
if (child.reset) {
child.reset();
}
});
You've got similar loop in your getAllChildren code - you might reset field at the same place.
The method is defined in Field type which is usually a supertype of each dialog widget. You can read more here.
My first question here so please accept my apologies if this has been asked before and/or I am making some newbie mistake!
I am trying to get my head around EmberJS with a simple exercise. I am trying to create a list of keywords and I have the basic functionality working. I wish to allow the user to enter a comma separated list of keywords to the store, however, alert if the keyword is a duplicate.
So I have an ArrayController with an Actions object and within which I have a createKeyword function.
createKeyword: function() {
// Get the keyword title set by the "New Keyword" text field
var entered_value = this.get('newKeyword');
if (!entered_value) { return false; }
if (!entered_value.trim()) { return; }
var entered_values = entered_value.split(",");
for ( var i=0; i<entered_values.length; i++){
var value = entered_values[i];
value = value.replace(/\+|"|'/g," ");
if ( ! value.trim() ){
continue;
}
value = value.toUpperCase();
alert( "Prior addition:" + this.get('length'));
// Prevent duplicates being added
if ( this.findBy('keyword',value) === undefined ) {
// Create the new Keyword model
var keyword = this.store.createRecord('keyword', {
value: value,
weighting: 1,
isNew: true
});
// Save the new model
keyword.save();
alert( "post addition:" + this.get('length') );
}
else {
alert( "Keyword [" + value + "] already defined");
}
}
// Clear the "New Keyword" text field
this.set('newKeyword', '');
}
I have a couple of alerts in there - one to display the array controller's length before I check for the value and subsequently createRecord on the store and one after. So I run this with 3 records, say 'tom','dick','harry' and if I add 'fred' to it, first alert is 3 and second alert is also 3 and fred appears.
I am confused as to why the 2nd alert is showing 3 and not 4 - I am assuming (perhaps incorrectly) that the arrayController has not yet been updated with the new record.
Secondly, if I restart then try adding fred,dick as an input, both get added, I would have thought fred should have been added and dick rejected as it was a duplicate.
Thanks in advance for any suggestions.
Jon
Judging by the way you wrote your code and that you use an 'ArrayController, I'm going to assume that the model for this particular route is all of your keywords. So themodel` hook is probably:
model: function() {
return this.get('store').findAll('keyword');
}
Assuming that, I think I can answer your questions.
First, the length doesn't change when you create the new record. It should increment from 3 to 4, but it doesn't. You are correct in assuming that the bindings haven't had time to update yet. You added the new record to the store, but the store hasn't had time to update the model for your controller yet because you still have control of the program flow. Most bindings are updated asynchronously in the run loop, so for many scenarios in Ember, you can't expect immediate updates.
Secondly, as for duplicates being added, it's hard to say but I think it's because you have a logic error.
// Prevent duplicates being added
if ( this.findBy('keyword',value) === undefined ) {
It seems to me as if you mistakenly put keyword instead of value. This might be just a typo when you were typing this question, but based on how you created your model, keyword is the type and value is the property.
Finally, a quick note: you shouldn't override the isNew property like you do when creating the new keyword. That will actually override the Ember-Data property with a permanent true value. (At least that's how I remember it working. I might be wrong, but it doesn't matter.) isNew is a computed property created by Ember-Data that will automatically update when the state of the object changes. Don't worry about setting it manually; just use the record as you normally would and Ember-Data will take care of the rest.
I'm using AmCharts to plot two lines on a line chart. They have some great documentation on how to use a function to customize the "balloon" (tooltip) text. However, it's not clear how I would go about distinguishing between the two data series in this custom function. At first glance it doesn't seem like there's any property in the GraphDataItem object to identify which series the data comes from.
Here's some pseduo code, for visual people:
graph.balloonFunction = adjustBalloonText;
function adjustBalloonText(graphDataItem, graph) {
if ( graphDataItem ...series?... == 1 ) {
return "something";
} else {
return "something else";
}
}
How do I do this?
Check GraphDataItem description:
http://docs.amcharts.com/3/javascriptcharts/GraphDataItem
It has a "category" property, also a reference to serialDataItem: http://docs.amcharts.com/3/javascriptcharts/SerialDataItem
Which contains all the information about series.
And finally, it has a reference to original data item from data provider (dataContext property). So you can store additional information in your data and then get it using dataContext.