TYPO3 sorting is not max value - mysql

I have a TYPO3 extension with over 2000 records that should be manuelly sorted. So I added the column "sorted" and set "sortby" => "sorted" in the TCA.
The newest record should have highest sort value.
Problem #1: Backend automatically sorts the records ASCENDING. So every time someone wants edit a record they have to manually switch to the last page of the extension list.
How can I correct the view in the backend?
I can't set ASC or DESC in the TCA sortby value because then the queries won't work anymore.
When I add a new record, the sorting value is the lowest one. So on a page with 2000 records sorted descending the new one never shows up! It's on the last position! How can I set the query so that new records have the highest sorting value?
The first problem is not that urgent but the second one - about new records - is really bad cause you can't work with the extension any more at all!

In TYPO3 it is important which button you use to insert a new record.
There are multiple Buttons. one at the headline and on sorted tables one at each record.
The usage of the button decides where the new record gets inserted in the line of existing records. The buttons at each record reads 'insert new record after this' and the top button means: 'insert at the top of the list'.
So your editors should first jump to the end of the table and then insert new records there. Otherwise you need to reposition the new record.
That can be done with the up and down buttons. That becomes nasty with many records.
But you also can reposition a record (or multiple records!) with the clipboard: sore the record in the clipboard and move it to the new position.
By using the multi-selection mode clipboard you can resort multiple records at once: insert the record one by one in the desired order to the clipboard and move them to the desired place. In this way you can record all records with just a few clicks:
E.g.
select a multi-select mode clipboard,
sort the records by name (clicking on the name column),
mark all records with the checkbox in the header,
insert all records in the clipboard (they are inserted in the current order),
(select Move Elements for the clipboard)
insert the records where you want them (at the top).
all records are inserted in the new order.

Related

Find out the specific row that was selected in Dash DataTable

I have a Dash DataTable with row_selectable set to "multi". Therefore, the user can select multiple rows via a checkbox that will appear next to each row of the DataTable.
I also have a callback that has as input Input("datatable-id", "selected_rows"). Therefore, each time the user selects a row, I get ALL the rows that are selected.
What I want to do is to update my database column is_selected based on the row that the user just selected. To get the row that the user just selected I can either:
Read my entire is_selected column of my database and find the difference between that and selected_rows.
Use selected_rows to update ALL the rows in my database.
I wonder, is there another better way to find out which specific row the user selected? So that I can simply update my single row in my database accordingly?
So, you can use a dcc.Store as a way to get access to the previous state.
If I'm not wrong, your problem is a comparison between two states: the state_0, the one before the interaction; and the state_1, the one after the interaction.
In that case, using only DashTable attributes, it is hard (at least I don't know how) to get the previous state of selected rows. With that in mind you can create a dcc.Store to store the last state of selected_rows to get access every time the callback is triggered. In other words, put the data as the Output off the callback and a State to get the access to state_0. Update the data with the current selected_rows after making a simple set difference between the current selected_rows and the previous one.

Mysql inserts in the middle instead at the end of table

I am new to database. I deleted few rows (till end of table) from a database table. Now every time i execute INSERT query via php, it inserts new row immediately after last deleted row and pushes the previous inserts down by one row.
As shown in above figure, the rows are deleted from 2019-08-18 (red rectangle) via the query:
DELETE FROM mytable WHERE date > '2019-08-18'
Now new inserts have wrong order as shown in green rectangle in above figure. Though the row with date 2019-08-19 is inserted first, it is pushed to the end of table.
What am i doing wrong?
Most relational databases will not return the rows in any particular order unless you ask explicitly. They'll just do whatever's easiest. Often that's insertion order, or maybe order on disk, or whatever index was last used. It's really arbitrary and may even change from version to version of the same database platform.
"If you cared you'd ask" is the principle at work here. You didn't ask, so MySQL presumes you don't care.
Add an ORDER BY clause to get predictable orders. Otherwise be prepared for the unexpected.

SQL Rowsource not working anymore after loading in values from another table

I have created a form whose comboboxes get "DISTINCT"-populated with values (from a table), which means nothing is selected at first, but the combobox offers a load of values to select from named table. In Field 1 I select a value and then Field 2 automatically loads in only values from the table where the criteria fits the value from the first field and so on. This way, I am narrowing down the numbers of applying recordsets from my table down to 1 or 2 just by clicking and choosing options. My Form looks this way.
I have a total of 16 rows where in each row I can narrow down parameters to 1 specific item from the table.
With pressing a button, I can write these values into another table where they will get a save ID and a save name. This all works flawlessly.
I also added a loading button, where I can select the savenames from the savetable and the form will automatically get filled with the values from the savetable. But as soon as I do this, no values are suggested anymore in the field that contains multiple Columns. I tried a Requery, I tried reassigning the Rowsource, I tried just deleting the values in the fields before, nothing helps. I have to use my "erase" function where I set all fields to "Null" to be able to get the "suggesting values" back to work.This is how it looks after loading
In the regarding field should be at least 3 values which get not displayed anymore.
It feels like filling the forms' fields with comboboxname.value = rs!valuefromsavetable deletes or blocks the rowsources from working.
Can someone help me here?

Best practice for handling positions of rows

What is the best practice for moving rows. So that you might want to change order of items. Now if you make a new column called order_id or something, wouldn't that fail if I delete or select rows.
Another method I guess is to just switch values completely with an primary ID, so just values except the ID are changed. however I do not know what people usually use. There are so many websites that give you the ability to change order of things.how so they do that?
Every SQL statement that returns a visible result set should include an ORDER BY clause so that the results are consistent. The Standard does not guarantee that the order of rows in a particular table will remain constant or consistent, even if obvious changes aren't made to the table.
What you use for your ORDER BY clause depends on the use case. A date value is the usual choice for a comment thread or blog entry ordering. However, if you want the user to be able to customize the order that a result set shows in, then you have to provide a column that represents the position of the row, and adjust the value of that column when the user makes changes to the order they see.
For example, if you decide that the column will contain a sequential number, starting with 1 for the first row, 2 for the second, etc. then you will be ok to delete rows when they need to be deleted without having to do updates. However, if you insert a row, you will need to give the row you insert the sequential number appropriate for it's position, and update all rows below that with their new position. Same goes for if you move a row from somewhere else to a new location; the rows between the new and old locations need to be updated with new postion indexes.

Calculated control does not recalc automatically

Firstly, a bit about my setup.
I have a primitive database of three tables:
A. Table that lists various locations: [location_code], [location_name]
B. Table that describes items: [item_code], [item_name], [item_price]
and finally a table that ties the roo^H^H^H whole database together
C. Table says which items are stored at each locations and in what quantities: [location_code], [item_code], [item_quantity]. This table can have multiple entries with the same [location_code], since different items can be stored at the same location. Basically, this is a schoolbook implementation of one-to-many relationship from locations to items, with a extra attribute (quantity) attached to each location-item link.
Now, all I need to do is to create a form that would list all items stored at certain location. This is a basic use-case for "subform" feature in Access. The main form simply navigates through different locations, while the subform lists the items.
I use
SELECT C.location_code, B.item_name, B.item_code, B.item_price, C.item_quantity
FROM B INNER JOIN C ON B.item_code=C.item_code
as a record source for the subform. The main form is linked to subform by [location_code]. The subform is set up with list layout (not table layout), i.e. each database field is given its own control element.
So far everything works perfectly. I select the location in the main form, and the subform gives me a list of editable [item_name]-[item_price]-[item_quantity] triplets for the current location.
As the next step, I want to add a calculated control to each of the above triplets. I want to know the total price for each kind of item (i.e. simply the [item_price] * [item_quantity] in each line). Easy, I add a calculated control to the "repeatable" area of the subform and specify
= [item_price] * [item_quantity]
as the formula for the value. Again, everything works perfectly. Now instead of the above triplets, my list has four entries per line: [item_name]-[item_price]-[item_quantity]-[total_item_price]. And, what is important, when I edit [item_price] or [item_quantity], the [total_item_price] gets automatically reevaluated once I finish editing.
And as the final step, I want to add another calculated control that would display the total price of all items stored at the current location (let's call it "grand total"). A also place that control into the subform (into the "footnote" area this time) and specify the following formula as its value
= SUM([item_price] * [item_quantity])
Now, this works. The total value is calculated correctly each time I change the location in the main form. Also, when I change [item_price] for any item at the current location, the grand total is also updated automatically. However, when I change [item_quantity], the grand total does not update (???). Hitting F9 will make it update. Changing the current location back and forth will update it. But, unfortunately, a mere change to [item_quantity] does not trigger an automatic update.
Does anyone know, what could be wrong here? Why do changes in [item_price] trigger the automatic update of the grand total, while changes in [item_quantity] do not? Intuitively, these fields seem to have the same status (except that the former comes from table B, while the latter comes from table C). Why is the behavior different? How do I make it update automatically?
In your subform's after update event, explicitly recalculate the total price control.
Me.txtTotalPrice.Requery
If you tab through the record and advance to the next record does it still not update. I am thinking that the price is the last field in tab order so when you change it, you tab on to the next record and the change is committed. If I am right then when you edit the quantity, your tab advances you to the price field which is still in the current record so the change is not committed to the table yet. If you advance further through, that should complete the processing.