Backbone.js Model with 2 parents - backbone.js

I would like to create a backbone based page where there are undefined amount of columns and rows in a table-like layout. The 'table' structure and cell data should be saved to the backend.
The simplified models are:
row:
id
label
column:
id
label
cell:
rowID
columnId
value
in this situation a cell belongs to one row and one column.
If I add rows and columns dynamically how will the cells know what their rowID and columnId is especially in case of a newly added row+column which is not saved yet?
An other question is how I can connect a row of cells to a row object and at the same time a column of cells to a column object?
Thank you in advance, please let me know if you need more details.

I would forget the concepts of rows and columns and just use index position for your cells.
If you have C columns and R rows, the cell at position Column = 2 and Row = 3 would be at position (3 - 1) * C + 2
This allows you to easily deal with changing numbers of columns and rows. You can also dynamically recalculate all objects that belong to a row or a column and then create object and row columns.

Related

Populate a row on a sheet for each item on a table and several other cells on another sheet

I'm trying to copy data from a data entry/form sheet "SalesEntry" to a "SalesLog" table on a separate sheet "SalesLog". As I have done before with this code (adapted from here):
Private Sub SaleEntry_Click()
Dim config, itm, arr
Dim rw As Range, listCols As ListColumns
Dim shtForm As Worksheet
Set shtForm = Worksheets("SalesEntry") '<< data source
With Sheets("SalesLog").ListObjects("SalesLog")
Set rw = .ListRows.Add.Range 'add a new row and get its Range
Set listCols = .ListColumns 'get the columns collection
End With
'array of strings with pairs of "[colname]<>[range address]"
config = Array("Fecha<>B3", "Client<>E3", "Product<>?", "Quantity<>?", "Total Sale Price<>?", "Tax Charges<>D26", "Customs Charges<>D27", " Shipping Charges<>D28", "Sale Channel<>B5", "Sale Channel ID<>E5", "Payment Channel<>B7", "Payment Status<>B9", "Amount payed<>E9")
' loop over each item in the config array and transfer the value to the appropriate column
For Each itm In config
arr = Split(itm, "<>") ' split to colname and cell address
rw.Cells(listCols(arr(0)).Index).Value = shtForm.Range(arr(1)).Value
Next itm
End Sub
This works great for storing the info from a few original scattered cells in the entry sheet.
However the problem I have is that in the entry sheet I have a table which contains the items sold on each order, and I need to create a row on the table for each of those items while duplicating the info from the fields on the entry sheet that are not on the items table.
Find below a screenshot of the data entry form. In blue is the items table and in red are the scattered values I'd like to paste for each item on the SalesLog table.
And this is how the resulting table should look:
I have read several articles, the documentation and some posts here, but I'm not sure about the solution. I really like the code above and how it stores data in an array and populates things easily.
So far I have 3 possible courses of action:
Merge and fill two arrays: Create an array for the scattered fields (above the items table) and create an array for the items table and then merging them using the items array as a secondary dimension and duplicating every other field array item for as many items in this secondary dimension. I know how to create the two arrays, but I'm not sure how to merge them into a bidimensional array and a few attemps I've made have returned an error.
Double For loop: Create a loop that appends the scattered cell values for each item in the items table and then looping that result into the SalesLog table, as per the original code above.
To me this is the most feasible solution but I'm not sure about the loop order and I think using a bunch of ReDim Preserve is not the correct way and at the end of some loops I get a 1004 error or nothing happening.
Use a collection?: As far as I have read and since the items will vary with each sale, I've read that collections are more suited; although the size of the array could be simply retrieved by counting rows in the items table before any operation. I have never worked with Collections before and honestly can't tell how to use it.
Can someone point me in the right direction??
I would also like to include a Now () Timestamp for each Row when the user uses the macro(clicks on the "Add sale" button)
Don't overthink this.
You want to generate a row for each item, so the easiest approach is to count the items in the table, then run a for loop and for each item in the table copy the data from the table row and the scattered fields.
This is pretty straightforward and you don't need to mess around with arrays or collections. Why make things more complicated than they need to be?
pseudo code:
myCount = Count rows in item table
for i = 1 to myCount
copy table cell1 in table row i' this is from the table
copy table cell2 in table row i' this is from the table
copy cell3 ' this is from somewhere else in the form
...
copy celln
next i

Filter row and populate

I have a form response sheet with different columns. I have a region column for every country. But when you respond to the form you have to select only one country. So in my sheet every row has only one country column filled. I would like to filter every row (and populate to automatically have new responses filtered) to have a new column with the region selected.
Sheet expected
In this case I only have 3 countries but in the real case I have about 40 countries.
Thanks for your help
try on row 1:
=ARRAYFORMULA(TRIM(TRANSPOSE(QUERY(TRANSPOSE(A:C);;999^99))))

How to count unique occurrences with criteria in excel

I'm using the below array formula to count the unique occurrences of text in column C using the agent name in column G as the reference. This is giving me multiple issues.
=SUM( --(FREQUENCY(IF(G3:G100000 = J5,MATCH(C3:C100000,C3:C100000,0)),ROW(C3:C100000) - ROW(C3) + 1) > 0))
Depending on the data set I'm using multiple agents will return a #N/A result and I can't figure out why.
Each dataset I'm using is 20k to 30k lines, so the formulas take a long time to process.
Any ideas how I could do this faster or better? Also any ideas why some agents get bad returns?
I am assuming that you are looking for the number of unique combinations of columns C and G.
Create a pivot table and check the box to add this data to the data model.
Drag both column headers to the Rows section, also drag one (of those same two) into the the values section.
click on the the field in the values section > value field settings > summarize values by > choose Distinct Count. This removes all duplicates.
Click the Row Labels filter and uncheck the blanks.
You can drop in new data then right-click on the pivot and refresh to see the new results. See the image.

Repeat Header Row With Each Row In the Table IN SSRS

I have a report in SSRS and I want it to display like this (header row repeats per data row):
Id Name
1 John
Id Name
2 Jack
How can I do that?
I have a row group which creates a new record for every new value of Id, but I can't get the header row to display before each record.
Don't use an actual header row. Add another row to your details group, and set the data in that row to be static text. (Type directly into the cell.)
The entire details group, no matter how many rows, will be repeated for each record in the dataset.
The details group is indicated by the small lines to the left that I circled in the screen shot below.

Add each row in a single cell

I have a requirement in ssrs report for display data like this.
I have to show 2 two rows data in one row in ssrs as shown below. Row count is unknown.
Please check another example.
Max two cell in one row in ssrs. I have to do this dynamically because I don't have any fix count in my data base table. If my table contain 3 rows it will display like first example but it it has 6 rows then it will looks like 2nd example.
Any suggestion how I can achieve.
The only way I know to do this left-to-right, top-to-bottom flow style is to sort of hack it in with lists. To my knowledge, the built-in controls do not directly support it.
First add a couple of columns to the query output to assign row and column numbers to each data row. (Change the order by clause as appropriate)
ceiling(row_number() over (order by AddressField) / 2.0) RowNumber
(row_number() over (order by AddressField) + 1) % 2 + 1 ColumnNumber
Now add a list to the report. Group by the RowNumber field. Within that list, add two more lists side by side. They will use the same dataset as the parent list. These will represent the cells. The left 'cell' will be a list with a filter ColumnNumber = 1. The right 'cell' will be a list with filter ColumnNumber = 2.
Now add textboxes within each 'cell' to contain the address data and format them as you desire.

Resources