AngularJs: After removing item from list, subsequent dirty form elements are set to pristine, how to handle this? - angularjs-ng-repeat

I have List of objects which I am iterating using ng-repeat.
List = [{
type = "CC",
cardNum : 125,
accNum : null,
amount =125,
isCard : true
},
{
type = "LN",
cardNum : null,
accNum : 125,
amount =125,
isCard = false
},
....
]
Now, based on selection from Radio of isCard (two radio, is Card and is Non Card), I need to show two respective field such as cardNum or accNum.
Now the problem is, when iterate and add both combination of isCard and isNonCard account and remove element in between, all the elements after that are set to pristine where it was dirty before.
scenario 1:
selected 1st as Card Acc - index 1
2nd as Non Card - index 2
3rd as card acc -index 3
touched the fields such that there is error for all 3 entries above
now, remove 2nd entry by using splice.
Issue: Now the 3rd element index is updated to 1(which is correct) but field is reset to pristine and error is hidden. How can I stop this so that error will still appear for 3rd element at updated index.

I managed to fix this issue. Even after using track by index, it did not work so I had to add trackIdentifier in object. Now when I tracked based on it, it started working and error messages appeared correctly.

Related

Google Sheets - How to Combine Filter Function with Filter View

I've been working on a spreadsheet with over 100 rows, and found a hacky way to incorporate a "hide" checkbox that will hide any row where column C matches a specific value (building type), specified beside the box. To do this, I first created a function like this: =FILTER(Data!A1, OR(Data!$C1<>$O$2, $P$2)) and dragged that across every row and column in a seperate sheet. This reads as, "Display current cell if the corresponding column C in that row in Data does not match the building type, or if the the checkbox is checked. This way, the whole row is hidden when the building type matches, and the box is unchecked. A1 adjusted to each row individually, $C1 referenced the building's type, $O$2 referenced the targeted type to potentially hide, and $P$2 was the checkbox.
Problem #1: This created a lot of formulas in hundreds of cells, and when the building type was not found, it displayed #N/A across the entire row. A Filter View was able to hide these values, but it was inconvenient to have to reset the values every time I wanted to hide or unhide another building type.
My Attempt to Fix: I used a filter function once again to recreate the entire sheet from one cell, hiding the appropriate rows, using this: =FILTER(Data!A2:J191, ARRAYFORMULA((Data!$C2:C191<>$O$2)+(Data!D2:D191*$P$2)) This is the hacky part. I multiplied the checkbox's "true" by an array arbitrary positive numerical values in the D column to "OR" it with each building type value to achieve the same goal as before, but for EVERY cell.
Problem #2 arose: When I get my beautiful sheet, I can not sort it via a filter view, or it will throw an error and display nothing. I'm resorting to sorting the original tab, but intend to have it be ignored entirely. So how do I combine these two, Filter View, and Filter Function, to create a nice spreadsheet where I can SORT AND HIDE rows?
Bonus Problem #3: To add more buttons, my formula is this: =FILTER(Data!A1:J191, ARRAYFORMULA((Data!$C1:C191<>$O$2)+(Data!D2:D192*$P$2)), ARRAYFORMULA((Data!$C1:C191<>$O$3)+(Data!D2:D192*$P$3)), ARRAYFORMULA((Data!$C1:C191<>$O$4)+(Data!D2:D192*$P$4)), ARRAYFORMULA((Data!$C1:C191<>$O$5)+(Data!D2:D192*$P$5)), ARRAYFORMULA((Data!$C1:C191<>$O$6)+(Data!D2:D192*$P$6)), ARRAYFORMULA((Data!$C1:C191<>$O$7)+(Data!D2:D192*$P$7)), ARRAYFORMULA((Data!$C1:C191<>$O$8)+(Data!D2:D192*$P$8)), ARRAYFORMULA((Data!$C1:C191<>$O$9)+(Data!D2:D192*$P$9))) This is ugly, and very slow to load. Is there a way to create a function range to handle the same checks on multiple rows, and crunch it into a single formula?
Here is another monstrosity (this one has less repetition) for you:
=QUERY(
{IGNORE!A2:J, IGNORE!P2:P},
"SELECT * "
& "WHERE Col3 is not null "
& IF(COUNTIF(P2:P9, False) = 0, "", "AND NOT Col3 MATCHES '^" & JOIN("$|^", IFNA(FILTER(O2:O9, P2:P9 = False))) & "$' ")
& IF(COUNTIF(A2:K2, ">0") = 0, "", "ORDER BY Col" & JOIN(", Col", IFNA(FILTER(COLUMN(A2:K2) & IF(COLUMN(A2:K2) = 1, "", " DESC"), A2:K2)))),
0
)
Your checkboxes should remain. The second row can have just True/False values, no need for column number (a simple change will be needed COUNTIF(A2:K2, ">0") -> COUNTIF(A2:K2, True)). Also consequent sort works now (but only in the actual order of columns: if checked 1, 3, 4 then it will be sorted first by 1, then by 2, then by 4). You could place another config table on the right about sorting, where you would select all the columns you wish to sort by, their mutual order, and desc/asc for them.
Edit: added IFNA so FILTER won't return an error, changed multiple ANDS to MATCHES and simple regexes.

Perfomance wise for LUA table selection

I'm a bit new to LUA. So I have a game that I need to capture the Entity and insert into the table. The maximum possible Entity table that could happen at the same time is 14. So I read that an array based solution is good.
But I saw that the table size increment even if we delete some value, for example from 10 table value and delete value at index 9 its not automatically shift the size when I want to insert table number 11.
Example:
local Table = {"hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello", "hello"}
-- Current Table size = 10
-- Perform delete at index 9
Table[9] = nil
-- Have new Entity to insert
Table[#Table + 1] = "New Value"
-- The table size will grow by the time the game extend.
So for this type of situation did array based table with nil value inside that grow by the time of new table value inserted will have better perfomance or should I move into table with key?
Or I should just stick with array based table and perform full cleanup when the table isnt used?
If you set an element in a table to nil, then that just stays there as a "hole" in your array.
tab = {1, 2, 3, 4}
tab[2] = nil
-- tab == {1, nil, 3, 4}
-- #tab is actually undefined and could be both 1 or 4 (or something completely unexpected)!
What you need to do is set the field to nil, then shift all the following fields to fill that hole. Luckily, Lua has a function for that, which is table.remove(table, index).
tab = {1, 2, 3, 4}
table.remove(tab, 2)
-- tab == {1, 3, 4}
-- #tab == 3
Keep in mind that this can get very slow as there's lots of memory access involved, so don't go applying this solution when you have a few million elements some day :)
While table.remove(Table, 9) will do the job in your case (removing field from "array" table and shifting remaining fields to fill the hole), you should first consider using "set" table instead.
If you:
- often remove/add elements
- don't care about their order
- often check if table contains a certain element
then the "set" table is your choice. Use it like so
local tab = {
["John"] = true,
["Jane"] = true,
["Bob"] = true,
}
Your elements will be stored as indices in a table.
Remove an element with
tab["Jane"] = nil
Test if table contains an element with
if tab["John"] then
-- tab contains "John"
Advantages compared to array table:
- this will eliminate performance overhead when removing an element because other elements will remain intact and no shifting is required
- checking if element exists in this table (which I assume is the main puspose of this table) is also faster than using array table because it no longer requires iterating over all the elements to find a match, the hash lookup is used instead
Note however that this approach doesn't let you have duplicate values as your elements, because tables can't contain duplicate keys. In that case you can use numbers as values to store the amount of times the element is duplicated in your set, e.g.
local tab = {
["John"] = 1,
["Jane"] = 2,
["Bob"] = 35,
}
Now you have 1 John, 2 Janes and 35 Bobs
https://www.lua.org/pil/11.5.html

dhtmlxgrid addRow() unusual behavior on checkbox

I am trying to add rows to a grid using dhtmlx in java, following is the code.
var combinedColumn = "displayText";
displayOptionsGrid.addRow(selectedID, [ displayOptionsGrid.getRowsNum() == 0 ? 1 : 0, combinedColumn]);
What the function is supposed to do is that if the number of rows is zero it adds the first row as checked and then the rest as unchecked. The error which I am facing is, I delete the rows one by one and try to re-add the rows in the same session with some other row at first than the row I added previously, but can't. I can only add the row which I added first previously as the first row.
When I use grid.clearAll() it works fine. Can someone tell me the exact thing we do in clearAll() which we don't in deleteSelectedRows() in dhtmlxgrid. Thanks.
Please, check your selectedID attribute.
Note that each row should have a unique id, so adding a row with the id existing in your grid will break the grid.

Errors when grouping by list in Power Query

I have a set of unique items (Index) to each of which are associated various elements of another set of items (in this case, dates).
In real life, if a date is associated with an index, an item associated with that index appeared in a file generated on that date. For combination of dates that actually occurs, I want to know which accounts were present.
let
Source = Table.FromRecords({
[Idx = 0, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}],
[Idx = 1, Dates = {#date(2016,2,1), #date(2016,2,2), #date(2016,2,3)}],
[Idx = 2, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]},
type table [Idx = number, Dates = {date}]),
// Group by
Grouped = Table.Group(Source, {"Dates"}, {{"Idx", each List.Combine({[Idx]}), type {number}}}),
// Clicking on the item in the top left corner generates this code:
Navigation = Grouped{[Dates={...}]}[Dates],
// Which returns this error: "Expression.Error: Value was not specified"
// My own code to reference the same value returns {0,2} as expected.
CorrectValue = Grouped{0}[Idx],
// If I re-make the table as below the above error does not occur.
ReMakeTable = Table.FromColumns(Table.ToColumns(Grouped), Table.ColumnNames(Grouped))
in ReMakeTable
It seems that I can use the results of this in my later work even without the Re-make (I just can't preview cells correctly), but I'd like to know if what's going on that causes the error and the odd code at the Navigation step, and why it disappears after the ReMakeTable step.
This happens because when you double click an item, the auto-generated code uses value filter instead of row index that you are using to get the single row from the table. And since you have a list as a value, it should be used instead of {...}. Probably UI isn't capable to work with lists in such a situation, and it inserts {...}, and this is indeed an incorrect value.
Thus, this line of code should look like:
Navigate = Grouped{[Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]}[Idx],
Then it will use value filter.
This is a bug in the UI. The index the UI calculates is incorrect: it should be 0 instead of [Dates={...}]. ... is a placeholder value, and it generates the "Value was not specified" exception if it is not replaced.

JSF dataTable to display a fixed number of rows

Greetings,
The context is myFaces 2.0.2, possibly also adding Tomahawk 20-1.1.10
I have created a dataTable (currently an h:dataTable, but could also be a t:dataTable using Tomahawk) displaying certain attibutes of a List<MyObject> in a backing bean. I have paging by returning only a subList of the List, and also sorting by click of column headers.
The next thing I need to do is ensure the table always shows a fixed number of rows. For example, if my page size is 5 and I have 12 items in the List, I need page three to show the last two items, plus 3 blank rows.
I have tried to "pad" the subList with both nulls and instances of myObject with null values, but this led to ConcurrentModificationException when hitting the last page of the table (the view was trying to getDisplayList even as the paging method was still adding the extra values.). I then tried padding the main list in the same manner, but then got NullPointers on my sort functions (a no-brainer in hind sight). Plus, these things are all addng overhead in the backer, when I would rather do this in the xhtml view.
(h:/t:)dataTable does have a rows attribute, but this specifies the maximum number of rows to display, not the minimum, as I need.
Ideas, please?
Don't pad the sublist. Pad the list. Preferably immediately after retrieving it in the bean.
The solution here was to pad the MAIN List, rather than the subList, using objects which are not null but whose attributes are null, and to add a null check into the Comparator:
if (obj1.getSomeValue() == null) {
return +1;
}
else if (obj2.getSomeValue() == null) {
return -1;
}
else {
// primary sorting code
}
Which ensures null items always come last. Works perfect.
BalusC did give me the push in the right direction, so I am accepting his answer.

Resources