Seven price
asked on
angularjs total rows
Just putting this out there. My example is there a way to have a total but after the total I can only change the total amount.
So if flag: true it will total the last 2 textboxes. But after it totals I want to change the total. For some cases a user will change the total and some cases the user will not. If you have a better way or even another object I can add to help this problem, will be greatly appreciated.
https://jsfiddle.net/seven snake/faoc 0Lrj/3/
So if flag: true it will total the last 2 textboxes. But after it totals I want to change the total. For some cases a user will change the total and some cases the user will not. If you have a better way or even another object I can add to help this problem, will be greatly appreciated.
https://jsfiddle.net/seven
ASKER
Have example
<input type="text" ng-model="total" ng-readonly="flag" />
ASKER
Doesn't work
I'm sorry but I don't understand the problem, and this is probably because the data is inconsistant.
The most important thging about develop,ment with Angular is the MVC paradign and the Model part is paramount.
Your data is an array of inconsistant rows, unit_price and quantity appearing in the first element, but quantity appears never again. mytotal appears only when flag is true, and it appears that you have in fact four groups - since group takes on four values. It looks like you want to display each element of the group with a total for that group, and a total for all the groups. And it appears from the question that for some groups the totals are not allowed to change.
I would suggest "redesigning" the data into an array of groups, each group being an object with the rows as an array, a total for that group and a flag or whatever to designate what you want to do with it. Once again, get the Model correct and the rest will be simple.
Hope that helps
The most important thging about develop,ment with Angular is the MVC paradign and the Model part is paramount.
Your data is an array of inconsistant rows, unit_price and quantity appearing in the first element, but quantity appears never again. mytotal appears only when flag is true, and it appears that you have in fact four groups - since group takes on four values. It looks like you want to display each element of the group with a total for that group, and a total for all the groups. And it appears from the question that for some groups the totals are not allowed to change.
I would suggest "redesigning" the data into an array of groups, each group being an object with the rows as an array, a total for that group and a flag or whatever to designate what you want to do with it. Once again, get the Model correct and the rest will be simple.
Hope that helps
ASKER
Well that is the purpose of asking if someone have a better idea on the design. everyone want the quick answer but cannot help solve the problem. Sometime if you like to help like I do on occasion I take time to see if there is a better way or more efficient way. Dont worry a true expert will help me figure a good way to design this function instead of quick ideas and bunch of talk. Thanks
I'm sorry, but I meant that in the nicest possible way. One needs to start with the data, and before I can add code I need to understand what the data represents. Obviously unit_price and quantity are clear, but what is the purpose of flag and group?
ASKER
Well the flag is just to identify the total of the group. But a user sometime needs to change the price manually of the total. They will only touch the total field if it changes. they will not touch the false input unless the want the total to match. I ask if another field or object can be added to get this working. I can invoke a object.
ASKER
Maybe using the $index but not sure to implement this with this function.
$index just tells you the row number. I don't see how that helps.
In a group of entries you want a subtotal which initially is the sum of the unit_prices times the quantities. The total at the end should be the sum of the subtotals. I presume that the user is not allowed to change the total at the end, but may change the subtotal. Does he do this by altering the quantity or price, or is he allowed to alter the subtotal field?
In a group of entries you want a subtotal which initially is the sum of the unit_prices times the quantities. The total at the end should be the sum of the subtotals. I presume that the user is not allowed to change the total at the end, but may change the subtotal. Does he do this by altering the quantity or price, or is he allowed to alter the subtotal field?
Abiding to your current model, here is one attempt. I am just checking the value of mytotal,
<div class="form-control2" ng-repeat="row in rows">
<!-- Attribute mytotal is set to 'total'-->
<span ng-if="row.mytotal == 'total'">
Total Group: {{row.group}}
<input type="number" style="font-weight: bold;" readonly class="form-control" ng-model="row.unit_price" ng-change="setTotals()"/>{ {row.mytot al}}
</span>
<!-- No Attribute mytotal -->
<span ng-if="!row.mytotal">
Group Item {{row.group}}: <input type="number" class="form-control" ng-model="row.unit_price" ng-change="setTotals()"/>
</span>
<br/>
</div>
<div style="padding-top:20px;"> Total of all rows: {{total | currency:'€'}}</div>
<div class="form-control2" ng-repeat="row in rows">
<!-- Attribute mytotal is set to 'total'-->
<span ng-if="row.mytotal == 'total'">
Total Group: {{row.group}}
<input type="number" style="font-weight: bold;" readonly class="form-control" ng-model="row.unit_price" ng-change="setTotals()"/>{
</span>
<!-- No Attribute mytotal -->
<span ng-if="!row.mytotal">
Group Item {{row.group}}: <input type="number" class="form-control" ng-model="row.unit_price" ng-change="setTotals()"/>
</span>
<br/>
</div>
<div style="padding-top:20px;">
ASKER
Please clarify your statement
For some cases a user will change the total and some cases the user will not.
What cases user will change and when he will not be allowed to change,
What he is changing ? Individual item in a group or group total ?
Also your has post. I see only Ok I added it to to the demo. but
Are there supposed be any more words ?
For some cases a user will change the total and some cases the user will not.
What cases user will change and when he will not be allowed to change,
What he is changing ? Individual item in a group or group total ?
Also your has post. I see only Ok I added it to to the demo. but
Are there supposed be any more words ?
ASKER
Sorry. the user will change the total only when a user enters into the total field. Other than that the total will calculate if a user types in any group that is false. Now the other problem is if there is a total in a single group and you type into group 1 and there is a single group like group 4. As soon as you type into group 1 group 4 goes blank or retrieves the total of group 1. Which is even weirder. ( if that is a word )
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Close my friend. but not just the single total editable but the other group totals must be editable also.
the algorithm is very difficult to come up with.
the algorithm is very difficult to come up with.
I see Pravin that you have added extra data to the original model. It seems to be that the data model consists of a set of groups with a summation. Each group consists of a set of objects each being a field quantity and a field unit_price. Each group has a summation of quantity times unit_price. This field is either editable or not. One presumes that the quantity and unit_price fields are not editable (?) and one presumes that quantity times unit_price need to be displayed(?)
The questioner has flattened this structure and in consequence added a group number. To denote the end of a group, a flag has also been added (as far as I can see)
So the data = { groups: [ ], total: 0} where the array is an array of {rows:[ ], subtotal:0, flag: true} (flag is false if the subtotal is not editable) and the rows array is an array of {unit_price:123, quantity: 0}
With this data structure it is relatively easy to generate the appropiate HTML (two iterations together with a test for editable or not).
The questioner has flattened this structure and in consequence added a group number. To denote the end of a group, a flag has also been added (as far as I can see)
So the data = { groups: [ ], total: 0} where the array is an array of {rows:[ ], subtotal:0, flag: true} (flag is false if the subtotal is not editable) and the rows array is an array of {unit_price:123, quantity: 0}
With this data structure it is relatively easy to generate the appropiate HTML (two iterations together with a test for editable or not).
ASKER
BigRat This structure is way beyond of a single row of data. Add a object to the json but adding additional input boxes defeats the purpose of what is needed to accomplish this. Theres another developer expert want to jump on this really bad. but he needs a day to come back into the country. The answer to this problem is not easy nor can anyone solve it. I found a problem looks like someone top of there game can only solve or bill gates.
>>This structure is way beyond of a single row of data.
Who said anything about a SINGLE row of data? I'm sorry to say, but your English is so bad we just don't understand the problem. This sentence, for example, makes no sense, sorry
>> I found a problem looks like someone top of there game can only solve or bill gates.
Who said anything about a SINGLE row of data? I'm sorry to say, but your English is so bad we just don't understand the problem. This sentence, for example, makes no sense, sorry
>> I found a problem looks like someone top of there game can only solve or bill gates.
ASKER
Understand this. You have an example of the obvious. I am not trying to be engrossed you but my mistake it is dyamic rows with on column. not 2 or 3. you have to be a little slow. Let me explain it like a baby Rat.
Like to edit the GROUP TOTAL. That means change the value after the total has been calculated for each group. CHANGE THE TOTAL IN GROUP TOTAL. CHANGE THE TOTAL IN GROUP TOTAL. CHANGE THE TOTAL IN GROUP Total can you understand that.
Like to edit the GROUP TOTAL. That means change the value after the total has been calculated for each group. CHANGE THE TOTAL IN GROUP TOTAL. CHANGE THE TOTAL IN GROUP TOTAL. CHANGE THE TOTAL IN GROUP Total can you understand that.
I'm sorry you feel that way, but if you must insult me, please try to get the English correct.
>> I am not trying to be engrossed you but my mistake it is dyamic rows with on column.
This sentence again makes no sense. Would you care to try in your own language, maybe I'd stand a better chance?
>> I am not trying to be engrossed you but my mistake it is dyamic rows with on column.
This sentence again makes no sense. Would you care to try in your own language, maybe I'd stand a better chance?
SevenSnake77,
Until now, I was very patient with you. But now looks like you have crossed the limit and using unacceptable language.
At the end of year, instead of thanking experts, you seem to be using curse word
From the trail of comments, one may conclude you were wasting everyone time and would like Bill Gates to answer your prayers
Normally I do not try to show off who I am. Definitely time permitting from your ranting and insulting others, check out my credentials at http://www.pravinasar.com
I have and can solve much tough problems.
Definitely you were not receptive and do not deserve advice from EE community.
I will recommend EE Admin to suspend or blacklist you for a while. Also I appeal other to send similar request to EE Admin. One bad apple can definitely ruin entire crop :)
Everyone: Have a wonderful year ahead. We look forward to Excellent 2016
Until now, I was very patient with you. But now looks like you have crossed the limit and using unacceptable language.
At the end of year, instead of thanking experts, you seem to be using curse word
From the trail of comments, one may conclude you were wasting everyone time and would like Bill Gates to answer your prayers
Normally I do not try to show off who I am. Definitely time permitting from your ranting and insulting others, check out my credentials at http://www.pravinasar.com
I have and can solve much tough problems.
Definitely you were not receptive and do not deserve advice from EE community.
I will recommend EE Admin to suspend or blacklist you for a while. Also I appeal other to send similar request to EE Admin. One bad apple can definitely ruin entire crop :)
Everyone: Have a wonderful year ahead. We look forward to Excellent 2016
ASKER
what ever. I been on here for 8 years and helped thousands and never been insulted. recommend what you want.
ASKER
Pravin Asar I have no problem with you. I think you came up with a great way I can see how I can possibly fix my problem .
You on the other hand have tried to help me and I do apologize. very unprofessional and I was having a bad day. Please forgive the out burst. Some guys just come on here to prove they can talk the talk but cannot walk the walk. I met a lot of guys in this business who get the job because of the articulate words but cannot program for anything.
again forgive me.
You on the other hand have tried to help me and I do apologize. very unprofessional and I was having a bad day. Please forgive the out burst. Some guys just come on here to prove they can talk the talk but cannot walk the walk. I met a lot of guys in this business who get the job because of the articulate words but cannot program for anything.
again forgive me.
ASKER
Thanks again.
e.g.
<input name="tb1" type="text" value="123' readonly>
Only thing is dynamically assign/remove the attribute based on the flag value.
Is the flag value changes when user is working in the form ??