Find out the specific row that was selected in Dash DataTable - plotly-dash

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.

Related

Table Data with sort, search query, pagination pass to different component in Angular

I will try to explain as simple as possible.
There is a table which in start gets first 30 rows of n rows and has sorting, search using mat-table. So even if it is sorted only the first 30 rows will be sent and when the user goes to next page it gets the next 30 rows from backend each time making a new request.
Now each row has a button that will take it to another component which will get some detailed data about the specific row.
This component has a previous and next feature that will get the detailed view of the next or previous row data in the same order that is displayed in the table(sorted, search Result, page number).
Currently the table rows are made again in backend(Django) with all the sort, search and other parameters then find the current row and send the next and previous row (will take minimum 5 hits on DB).
Hence it very slow.
In Frontend I can only pass the data of only that page, which will have problem in next or previous page.
How to properly tackle this...
Normal search UIs don't focus on 30 rows at a time. Instead, they first search the entire dataset, then 'paginate' the results. (Or is that what you intended to say?)
There are details that can let the processing work fast, or there may be details that prevent speed. Please go into details about the table structure and the possible search criteria.

TYPO3 sorting is not max value

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.

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?

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.

Determine whether row is selected in MS Access 2007 List Box

I have a situation where I want to associate multiple values from one table with a value from another. I've got my data structured with a many-to-many join table in between, and I'm trying to manage the membership in the join table.
This question is about the UI portion of the process. I think that what I want to do is to present the user with a multi-select List Box control on a form that holds the ID of TableA constant (and, incidentally, hidden). The List would be populated with all the (fairly short list of) rows from TableB (descriptions displayed, IDs in hidden column). On load, I'd select those rows of the list that participate in the M-M join. The user could select additions and/or deselect removals.
What I'm not sure about is how to tell whether or not any given row is selected. I know about the IsSelected collection--if I were just adding, I'd walk that with For Each, but I need to remove any that have been deselected, and I need to not re-add any that already exist. What I'm thinking at this point is walking the whole list, testing each selected value & inserting it if not already present, and testing each un-selected value for possible deletion (hmmm--that's starting to sound needlessly complex....).
What I started out to ask was "how do I tell if row(x) is selected?" I'd still like the answer to that, but I'm open to other suggestions for managing the base problem, as well
In seems that you have a list that you are using to create the selected items. After the user has updated the list box, you can compare .ItemsSelected to the rows of the list that participate in the M-M join. Missing items can be deleted and additional items can be added. A few very rough notes:
For Each itm In Me.AList.ItemsSelected
rsJoinList.Find "ID=" & Me.AList.Column(0, itm)
If rsJoinList.NoMatch Then
'To be added
Else
'To be deleted
End If
Next