Use angular2 trackBy to update - angular2-template

I have a collection of items and I want to show it in table via ngFor.
In order to improve perfomance I uses trackBy.
My questions are:
1. How can I use trackBy to item update (not only if item added/delete)?
2. How can I catch the event of row update?

Related

SQL - "deleting" a row by setting all columns to NULL

I'm new to .net.
I have a task at hand for my .net web project, using entity framework.
The task is: To delete a certain row in the db called Products using a webpage interface.
What I have right now: A webpage that displays all the rows in that db, with a button on the side for each row ( that doesn't have any logic behind it yet ), that is supposed to mean the delete button.
How I plan to delete the row: When the button is clicked, it should set all the contents of that row's columns to NULL and save it in the db.
The question is: Is that a viable solution for deleting a row? Could there be any problems in the future if I use that method for deleting the row? Are there maybe better solutions for that task?
i suggest that that you set , for instance the idProduct to -1 (assuming that the id are always positive) since you don't want to delete it directly and Handel the db separately by using a trigger that launches when you update the product table
CREATE TRIGGER tr_onUpdate_delete
ON product
AFTER UPDATE
AS
if (select idProduct from inserted) = -1
begin
DELETE FROM product WHERE id=(select idProduct from deleted)
end
and please note that : i assume that you are updating one row only every time

Is it possible to hard delete a Directus item through the API or app?

Deleting an item from a collection, which has a status field, through the UI or API results in the item being soft deleted. However, in this one particular instance, we want to remove it from the database entirely.
If not possible, can it safely be done through the database by just deleting it from the table carrying the name of the collection? Any side-effects when doing it this way?
Found the answer on this page https://v8.docs.directus.io/guides/status.html#soft-delete:
When deleting an item, the API does the following:
Check if the collection has a status field
Check if the delta data has the status field (meaning the status was changed)
Check if the new status value (from delta data) has soft_delete = true
If yes, it sets the action to SOFT_DELETE
If no, it hard deletes the item (permanently removed from the database)

Duplicate keys when adding products in Vuetify Data Table

I am currently using a Vuetify Data Table where you can add products to. In the end I want to do a calculation based on the price of all those products. The products all have an ID, but when I add those products to the Data Table it gives me the following error:
Duplicate keys detected: '12'. This may cause an update error.
I understand this happens because I use the ID of the product. But how can I prevent that it is giving me this error? Should I pass a completely different ID instead of the one of the product itself? I might need the product ID later. I would like to know what would be the best solution. Thanks in advance.
I suggest you to add a column with an unique id. If you have an array of objects:
array.forEach((item, i) => {
item.subId = i + 1;
})
Then in your Data Table set the item-key to subId.

How do I set up a MS Access form to create a new row in table and set one field as a default value?

So I am not positive I am even asking the correct question, but here it goes. I currently have a MS Access Form built so that someone can enter in a new work order. You are able to set the company, the part number wanted, quantity, and the Work Order number is an auto generated value that I use for my primary key. All of that works great and successfully adds a new row to the table "Work Orders". However, when this form is used to create a new work order I want the last field in the table "Work Orders" which is called "Status" to be set to "Not Started".
I successfully made an update query that asks for the Work Order Number, and will set the "Status" field to "Not Started". Here is the code for that:
UPDATE 03A_WorkOrderList
SET 03A_WorkOrderList.Status = "Not Started"
WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));
If you give the update query work order number everything works great and the "Status" field is updated.
So back to the form I decided to attach the update query to the build event where the update happens after the new line is created. That seems to have worked too except it asks for the work order number. I totally understand why because it is the code that is in the update query of : WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));
What I cannot figure out is how to have it pull the work order number that was automatically generated and use that for the update query.
If I am going about this all wrong, please let me know. TIA.
In Ms Access, open your [Work order] table in design mode. Select the Status field and in the property section below, you can set the Default value to be Not started. This way you don't need to perform an update and all new orders will automatically have Not started status.
or in your add order form, On before update event, you can set the status = 'Not started'
I was able to get the functionality that I was looking for with the following UPDATE Query:
UPDATE 03A_WorkOrderList SET 03A_WorkOrderList.Status = "Not Started"
WHERE [03A_WorkOrderList].WO_Num=(SELECT MAX(WO_Num) FROM 03A_WorkOrderList);
Since the WO_Num is auto generated and I want to edit the very same one I was working on, I could just look for the MAX(WO_Num). I then made this UPDATE query apart of the build event of the order form.

Add a Record To Last Of The Table [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
When I use below query to add new record to the table (at unknown), the new records added to first of table .
I want to add new records to the last of table .
this my code :
begin
insert into TBLCrowler (Url,Title,ParentId,HasData) values (#Url,#Title,#ParentId,#HasData)
end
select top 1 CatId, Title, ParentId, Url, CrawlerCheck from TBLCrowler where CatId=(Select min(CatId) from TBLCrowler where CrawlerCheck=1)
update TBLCrowler set CrawlerCheck=2 , HasData=2
where CatId=(Select min(CatId) from TBLCrowler where CrawlerCheck=1)
Okay, once more into the breach.
You are using a relational database. It's not a worksheet, it's not a rectangular array of cells in a word document. It's power is reliant on being able to store and retrieve records in the most efficient way possible.
Ordering is either implied through an index, which the DBMS is free to ignore, and which could change anyway, or explicitly required through an order by statement
If you want things ordered by the time they were added to the table, you add a created_at column and populate it at the time you perform the insert.
Then when you select from it you add Order By Created_At to your select statement.
If you want that ordering to be "fast" you add an index on the Created_At column, which then DBMS will make a brave attempt at using the index in order to avoid the cost of a full pass sort.
Step back and think for a minute about how you would write a DBMS. What would the cost of your implicit orderedness be. Any change to any but the "last" record in the "last" table would mean rewriting to disk every record in every table "after" it. Insert is worse, Delete is as bad and that's without considering that different records take up different amounts of space.
So throw first and last in the bin, if you can find them...