Adding a datagrid inside another datagrid - dojo

I have a datagrid that uses a data structure like:
[
{
name: "test"
sub_things: [ { name: "blah" }]
}
]
Each row will have varying numbers of sub things and I an trying to add them as subrows in a row in the datagrid by adding another datagrid in the cell formatter, but cant seem to get it added. How would I acheive this? Or is there a better way?

What you are looking for exists! Check it out: subgrids!

Putting datagrids in datagrids, even if you can figure out how to do it sounds like a recipe for slowing down the browser or making it explode.
You could consider a few things:
Make this into a two step process. The first datagrid just has the name "test" and maybe a brief summary of sub_things. When you click on a row, it opens a new grid on another tab or maybe on the right side which contains the sub things just for that item.
You could use multi row layout of the datagrid like explained on this page (scroll down a bit for the multirow examples)
http://www.sitepen.com/blog/2008/07/14/dojo-12-grid/
You could have a combox box with a type ahead suggest of the main items and when one item is selected, then render a datagrid below it with the sub items.
By nesting grids in grids you are going to create a usability nightmare, so I would really recommend focusing on how to limit the data shown to the user and keep it as simple as possible.

Related

BIRT result set values in specific cells

My query returns location_cd(string) and item_count(int). I only need certain rows from the result however and I need them to display in specific places in my layout so I don't think the table solution is going to work. Can I determine where I place the value for a particular row of the result set?
I am using a grid to display values for a number of fields. I cannot seem to be able to get the values from the results to show. The grid is bound to the result set. I even tried binding the cells to the result set but that didn't work either.
I checked in the query editor and there is a result set shown in the Preview so I know the query works. The complete and correct result set shows if I put a table on the page.
I tried inserting a Dynamic Text or Data object in a cell and used the expression:
dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:""
This returns a blank and does not seem to evaluate. I tested it with :
dataSetRow["location_cd"]=="3SD"?dataSetRow["item_count"]:"BLANK"
and got 'BLANK' to appear in that cell.
dataSetRow["location_cd"] and dataSetRow["item_count"] will display the location_cd and item_count from the first row of the result set. row.outer[] did the same thing. Obviously I am just hacking at this report at this point.
A co-worker suggested that she uses a JAVA if-statement in places like this but I could not get that to work either.
Any ideas or suggestions that will get me on the right road??
Thanks
An elegant option would be to use a HashMap storing the result of the dataset.
Declare a report variable named "values", with a new hashmap as default value (see image below)
Fill values in the onFetch script of the dataset: vars["values"].put(row["location_cd"],row["item_count"]);
Insert new data elements at any place of the report with expressions such: vars["values"].get("myFavoriteLocationCD");
Though it is important to note the dataset should be triggered by the report before these data elements.
The particular row you want to display you specify in a "Text" field inside your grid. Just drag and drop a "Text" field inside your grid. If you bound the fields you want to display to your grid, the "Text" field inside the grid inherits the bindings of its parent (the grid), so you can access the bindings automatically in the "Text" field.
You could try following steps, maybe that works.
Don't use "Dynamic Text" field, instead use a regular "Text" field
Ensure the fields of your query which you use, are bound to the grid (you sayed you already did)
Open the "Text" field
Change preselected pull-down entry "Auto" into "HTML"
Change preselected pull-down entry "Formatting" into "Dynamic Text"
Wrap your code in <value-of format="HTML"> your code goes here... </value-of>
Note: You should check in the "Expression Builder" of your "Text" field if you are able to access the fields you bound to the grid. If they are not available sth. went wrong with your binding. Avoid binding query records to cells this will drive you crazy.
If you want to display a list, ensure you didn't set a constant height in the row of your grid. Set the height to 100% than the row takes its height dynamically.
What about the idea to optimize your query, that only get the results you want are displayed, than you don’t need to filter them with java script? If you don’t need the filtered results in another place this would be the cleaner solution in my opinion.

Assigning DataGridView_1 (DGV) to DGV_2 and DGV_2 doesn't update

I have successfully found an answer to every question I ever had since I started with VB.NET 2 years ago by trawling forums, but this time I failed, and I decided to join my favourite forum where I have always found the best answers. This one :-)
I am somewhat of a beginner, so load you flack-guns 'cause here we go...
In my main form I have a DGV (called "gridDisplay") to display data. This DGV is a read only one as it is only used to disply data, not to inteact with it.
I have any number copies of a class (called "TaskData") that holds data to be displayed, and the data to be shown in the main form is that of the active "TaskData" class.
I came up with the brilliant (I have my doubts now...) idea to let the TaskData class make a DGV as it knows what data is in it and how to display it, and then all I had to do in the main form was to set the DGV there to that of the Active TaskData Class (see code below)
With ActiveTask
'Assign the active DataDisplay to the one in the main form
Me.gridDisplay = .TaskData.DataDisplay
Me.gridDisplay.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
Me.gridDisplay.Refresh() 'Trying to make it update
Me.gridDisplay.Update() 'Trying to make it update
MsgBox("Row count: " & Me.gridDisplay.RowCount)
End With
Ok, so the DGV in the .TaskData.DataDisplay has one column and 500 rows. The One in the main form is set up with a default of 2 columns and no rows (set up in the designer)
After the code above, nothing happens visually in the main form. Still 2 columns and 0 rows. However, the text box says: "Row count: 500" And if I put a break point there I can inspect Me.gridDisplay and it has all the data that should be there.
Why doesn't it show up?
Am I doing something unwise by assigning one DGV to another?
Any help would be much appreciated.
Any constructive critizism equally so :-)
I think you should call the datasource again before
Me.gridDisplay.Refresh()Me.gridDisplay.Update()
Something like this,
gridDisplay.DataSource = dataset.Tables["your table"];

data from Gridview to textbox

i have a form with datagridview in vb.net that show my data in columns. what i'm trying to accomplish is that after choosing a row and pressing Edit button a new form will open and split the row for the right text boxes to update the data. the datagridview row shows different types of data: name,email,date,etc... any idea? Thanks in advance!
In the EditButton click-handler, you may access the selected row in your datagridview with the MyDataGridView.CurrentRow property.
This object - a DataGridViewRow - has Cells, which you can access individually by index and then get to their values:
...CurrentRow.Cells(n).Value
This then, in turn, you may use to fill the items in your edit form.
After completing your edit form, retrieve the (updated) values and put them back into the CurrentRow.Cells(n).Value
If your datagridview is databound, then you can also work directly with the datastore, through
...CurrentRow.DataBoundItem
The type of this object depends of course on your configuration; it may, for instance, be a DataRow.
This should be enough to get you going.
Final note on your added remark "thanks ...": you're apparently new at this site. I'm not sure why you got "downvotes". It may be because your question is rather elementary ("homework"), or people found your problem description not clear/detailed enough. Please, understand that answers (if any) are provided "unpaid for", and require "voluntary" effort from the contributors. Understandably they prefer that YOU do most of the work/study/trying, before asking someone else "to do your work for you". No offense intended.

Gray out a form row's (detail's) button conditionally with VBA code

I have a standard form in MS-Access which lists a bunch of orders, and each row contains order no, customer, etc fields + a button to view notes and attached document files.
On request from our customer we should gray out the button btnAnm (or check or uncheck a checkbox) depending on a calculation from two queries to two other tables (a SELECT COUNT WHERE and a check if a text field is empty).
I've tried btnAnm_BeforeUpdate(...) and btnAnm_BeforeRender(...) and put breakpoints in the subs, but none of them trigger. The same if I use the control Ordernr instead of btnAnm.
I'd like a function in the Detail VBA code to be triggered for each "Me." (row) so to speak, and set the row's control's properties in that sub.
What do I do? I've looked at the help file and searched here.
*Edit: So I want to do something that "isn't made to work that way"? Ie. events are not triggered in Details.
As an alternative, could I base the value of a checkbox on each line on a query based on the 'Ordernr' field of the current row and the result of a SELECT COUNT from another table and empty field check?
Do I do this in the query the list is based on, or can I bind the extra checkbox field to a query?
A description of how to do this (combine a COUNT and a WHERE "not empty" to yes/no checkbox value) would be perfectly acceptable, I think! :)*
You cannot do much with an unbound control in a continuous form, anything you do will only apply to the current record. You can use a bound control with a click event so that it acts like a button.
Presumably the related documents have a reference to the order number that appears on your form, which means that you can create a control, let us call it CountOrders, with a ControlSource like so:
=DCount("OrderID","QueryName","OrderID=" & [OrderID])
The control can be hidden, or you can set it up to return true or False for use with a textbox, you can also use it for Conditional Formatting, but sadly, not for command buttons.
Expression Is [CountOrders]>0
You can also hide the contents and add a click event so that is acts in place of the command button. Conditional Formatting will allow you to enable or disable a textbox.
As I understand your question, you have a continuous form with as command button that appears on each row - and you'd like to enable/disable the button conditionally depending on the contents of the row.
Unfortunately you can't do that. It seems that you can't reference the individual command buttons separately.
Having wanted to do something similar in the past I came up with two alternate ways of setting up my interface.
Put a trap into the onClick code for the Button. Which is icky, because it is counter intuitive to the user. But it gets you that functionality now.
Move the command button (and editable fields) up into the form header, and make the rows read only. Your users then interact with the record only in the header, and select the record they want work with in the list below. As I recall this is known a Master-Detail interface.

Grids get empty when I click on some other tab

I have a question, I have a combo box, which when changed fills the data grid. Now Wen I change the Tab and come back to same tab again(one containing the combo box)..the value of combo box remains there, however the grid gets empty. I need this data to be maintained till the user selects another value from drop down.How can this be done???
Any suggestions would be appreciated.
Some of the possible reasons :
There is a MyDataGrid.clear somewhere
The DataSource used to fill the grid is somewhere cleared.
If you use a DataSet, your DataTable is somewhere truncated.
If you use a BindingSource as your DataSource, maybe somewhere else you're using the same BindingSource, which empties the grid.
I would recommend you to put a braekpoint on your Combobox change value event to see if it's not called with a wrong value somewhere else.
And I would add a spy to check your DataGrid (the number of lines for example) to precisely know where it happens by executing my code step by step.
Hope this helps !