Ext.form.field.Number - formatting the value - extjs

I have an Ext.form.field.Number where I can insert a number or use the spinner to select one.
How do I format this value for display in the Ext.form.field.Number field?
Let's say I want to have displayed, when you spin up or down:
1st
2nd
3rd
...
or
one
two
three
...

I believe, Extjs supporting ordinal number only for date
Please Refer Here
You can use this function to achieve that
function getGetOrdinal(n) {
var s=["th","st","nd","rd"],
v=n%100;
return n+(s[(v-20)%10]||s[v]||s[0]);
}

Related

How to create new line in react table column with lots of data

I am using react table. I am calling a method on API (.NET), which concatenates some fields and now I need to display this concatenated field in react table column.
From API I tried to put /n in the column so that it renders a new line on UI (inside react table). But no luck. Example: I need to display
This field is calculated by adding two numbers 10 and 20. Since the
result is greater than 15 you cannot perform this operation.
In the displayed text, what I want is "Since" should start in a new line in react table.
I tried to put {'\n'} before "Since" but it did not work. Any ideas how to achieve this?
The '\n' escape character does not work in HTML. You have to work with
other HTML solutions like using <br> or divs to get a multiline
implementation working.
You solve this quite easily. when getting the string append a special char like the comma (,) or some other char that you are sure would not be used in your original text.
Then get that string to a js variable in your react app.
let multiLineString = "This field is calculated by adding two numbers 10 and 20. , Since the result is greater than 15 you cannot perform this operation";
let lines = multiLineString.split(',')
let linesHTML = lines.map((line)=><div>{line}</div>);
now render this variable anywhere you want, you will get a multi line string implementation.
Of course the better approach would be to get a json array of values from the back end.

How can I change an Element in an array, that contains a specific String?

As it is said in the title I could use some help regarding a problem I have with my App.
My App scans a Barcode and offers to safe this barcode in a table together with a second String that can be put in which describes the number of times you want to save this barcode.
The customInit of the cell displays this as the barcode on the left and a grey number on the right representing the count. All of this information is saved in an array of form list=["972537657, 12"; ...]
My last functionality I want to implement is to have a function check for a maybe already existing barcode in the table and if there is instead of inserting a new row with the same barcode and a different number I want my app to just add the number I put in , to the number of the already existing table element with this specific barcode.
My problem: The logic in this works fine ; if there is an already existing element execute this function if not just insert a new row with the input data.
But I Have no idea how to tell the app what to change and how I can access this element of the array.
Maybe someone has an idea (I can also add some of my code if someone would like to inspect my problem further)
First, find the index of the string your looking for, then remove it and insert it at the index.
let arr:Array = ["a","b","c"]
let indexOfA = arr.index(of: "a")
arr.remove(at: indexOfA)
arr.insert("YourString", at: indexOfA)
if you only care about the duplication, why don't use Set instead of Array.
var barcode:Set = ["972537657","972537651","972537653"]
let result = barcode.insert("972537651")
if result.inserted {
print("insert")
}else {
print("duplication")
}

angular way to use number with comma and dot to calculate another value

I am using angularJS and Angular Material Design.
For one of the amount field i have input box as below which displays calculated field.
Whenever the value is stored it is stored as comma separated i.e. 19,999.9984 which is not a problem for me.
But whenever i use this value for another calculation, i get NaN.
$scope.txn.toUnits = $scope.txn.toAmount / $scope.txn.toPrice
Above expression end up with NaN since there is a comma in toAmount value 19,999.9984
Is there any angular way to resolve this ?
You could use the parseFloat function
This is a best solution to do this if it interests you :
http://numeraljs.com/

Angularjs: default value when current option not in domain of select

I have cascading select where the value in the first decided what should be the option of others.
When I change the value of the first select so that the currently selected value in one other is no more a possible choice, I get a null (empty) choice. In place, I want to get a default, not null, value (of course, I don't want to reset to a default value is the choice is still legit).
I looked to (rather) similar question like Why does AngularJS include an empty option in select? but is does not seem to work, perhaps because my options are not predefined but generated on change.
I set-up a jsfiddle with the actual code: http://jsfiddle.net/sXu9a/
choose 2 hours or greater on the first select
chosse 1 in the second select (start hour)
choose back less than 1 hour in the first select
=> the second select display a empty option, and the "startHour" model still contains the last selected value (which is no more a valid choice). I really want to update the ng-model for that option to be reseted to 0.
In fact, I would like to be able to encode the condition: "if current model value for selected option is not in the set of possible value, reassign to model a default value (0)". So I tried a "onChange" like that:
$scope.onChangeInterval = function() {
if(jQuery.inArray($scope.agentSchedule.startHour, $scope.startHours() ) ) {
$scope.agentSchedule.startHour = $scope.startHours()[0];
}
}
But that does not seem to work.
Any idea about that ?
So, it happens that the "onChange" solution DOES work, as long as you don't make typos in the variable of your name. So with the following code (onChange is called on the first select):
$scope.onChangeInterval = function() {
if(jQuery.inArray($scope.agentSchedule.startHour, $scope.hours() ) ) {
$scope.agentSchedule.startHour = $scope.hours()[0];
}
}
Sorry for the noise!

Renderer in ext-js

What is (in summary) the function of the renderer in ext js?
A renderer is basically the function responsible for showing the underlying data to the user in a fashion or format that looks nice or makes sense.
Some examples might make it more clear:
A date renderer could take a javascript Date object and format it nicely like:
January 27, 2011
A number renderer could take a number like 2.23535346 and format it to 2 decimals like:
2.26
A renderer could even take a string like 'Y' or 'N' and instead show it as an image like:
Basically, the sky is the limit.
The renderer allows you to format data from a store in any way you see fit. It's a function that takes an data value and can return HTML. This is used to keep code that generates HTML separate from the code that generates the data.
Renderes transforms the value of display field into custom fashion.
let say i want to display any prize value into dollar
{ xtype:'displayfield',
name:'name',
value:'45',
renderer:this.transformIntoDollarConvention
}
here, transformIntoDollarConvention is a function defind above the constructor with a return statemnt .
transformIntoDollarConvention:function(value)
{
return value+'$';
}

Resources