aggrid angular8 select drop down in column - ag-grid-angular

I am implementing aggrid enterprise version in my angular 8 project.
I am having the following requirement:
1)I need a select drop down in aggrid columns so that user can select the value from drop down and once we select a new value from drop down we should fetch the corresponding id instead of the label.
for example:
I have a vendor cell in agrid which we want to display select drop down.
From API I am getting the following rows for vendor:
vendor = [{
"id": 1,
"name": "Test_Vendor"
},
{
"id": 2,
"name": "Test_Vendor5"
}
]
In the grid column for vendor we should show the vendor name as select drop down.If user select a different vendor name we should fetch the 'id' of cell instead of vendor name.

In this link there is an example to add a button in the row, You can use this to add a selectBox to the grid. You have to change the frameworkComponents and cellRenderer in the columnDefs

Related

Bind JSON to build a dynamic form in AngularJs for One-To-Many relationship and having parent-child relations in both the tables

I have two database tables with a one-to-many relationship between them and the parent-child relationship within each of the tables. Here reference table (one side) works as a master table and the reference_copies table (many side) works as replicas of the master.
I want to create UI form in AngularJS to provide insert/update functionalities to the user. As shown in UI_image, user can go up to the n number of level as he/she wants. Also attached the image with database tables structure.
In reference_copies table, data can already exist as we are uploading through excels too. Here, name & type_id columns combining together create unique constraints. So while the user tries to add a level, I need to check if the name exists for that type or not. If exists then fetch the object else save and fetch the saved object (with created id). Here value and selected type will be the same for all levels so the user needs to select only once.
On the final submit, the master form's each level will be mapped with corresponding reference copies' each level. i.e. parent name of a master will be mapped with parent names of reference_copies 1, 2... Likewise, level1 of a master will be mapped with level1 of reference_copies 1& 2. and so on. If there is no corresponding level in either of the form, nothing happens, that level will not be mapped with any. Here, there are no restrictions to create similarity in levels. As shown in the example, the master form is having two levels, reference copy 1 form is having only one level and reference copy 2 form is having 3 levels.
On final Submit button, I want to build the json payload as below: Also when I get the response json in below format with IDs, the form should be filled as shown in above for the update.
{
"name": "Reference Name",
"childs": [
{
"name": "child level1 name",
"childs": [
{
"name": "childlevel2 name",
"childs":[],
"referenceCopies": [
{
"id" : 2004
}
]
}
],
"referenceCopies": [
{
"id": 2001
},
{
"id": 2003
}
]
}
],
"referenceCopies": [
{
"id": 2000
},
{
"id": 2002
}
]
}
I tried with recursive template in AngularJS to achieve this but it's not working. Can anyone provide some demo or suggestion to achieve above kind of requirement.
Please let me know if the above description is incomplete or unclear.

Use Google App Script to change secondary sort column

I have sheets that have a data range connected to a pivot table. The pivot table has a secondary row sor by the last column. I have queries that update the data range and add a column. I would like to be able to use Google App Script to sort by that new column. I can get the current pivot table and seem to be updating it but the changes do not seem to be happening. I used the method here. The original table
I used the method here. The original table is as follows:
`
{
"columns":[
{
"sortOrder":"ASCENDING",
"sourceColumnOffset":2
}
],
"values":[
{
"summarizeFunction":"SUM",
"sourceColumnOffset":4
}
],
"source":{
"endColumnIndex":5,
"startRowIndex":6,
"endRowIndex":193,
"sheetId":698433721,
"startColumnIndex":0
},
"rows":[
{
"valueBucket":{
"buckets":[
{
"stringValue":"6/26/2019"
}
]
},
"showTotals":true,
"sortOrder":"DESCENDING",
"sourceColumnOffset":3
}
]
}
'
The 'stringValue" contains the text of the header of the current column. I assume that changing that would change the sort column but it has no effect.
When I read the pivot table again after making the change the new data shows up but the UI representation of the pivot table does not change and the sort column does not change.
Are you replacing the whole pivot table? I think the documentation sets this as a requirement no? To quote >>'Essentially, editing a pivot table requires replacing it with a new one'<<.

Json to excel using power query

I have some json on a website that i want to convert to excel using the power query option from web. But I ran into a small problem. My json looks like this:
[
{
"id" : 1,
"visitors" : 26,
"some_number" : 1,
"value" : 3500
},
{
"id" : 2,
"visitors" : 21,
"some_number" : 5,
"value" : 2000
}
]
but when i use from web i get this:
I can drill down into a record,convert it to a table, transpose and use first row as header but then i get just one row. How can i get all of my data to the table and not just one row?
First I would use the List Tools / Transform menu (it should be automatically selected) and click the To Table button. This will give you a single-column table with 2 rows. Then I would click the small Expand button - it will appear in the column headings, just to the right of "Column1". Uncheck the Use original column name ... option and you will get a table of 4 columns and 2 rows.
Here's the full script I generated:
let
Source = Json.Document(File.Contents("C:\Users\Mike.Honey\Downloads\json2.json")),
#"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Expanded Column2" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"id", "visitors", "some_number", "value"}, {"id", "visitors", "some_number", "value"})
in
#"Expanded Column2"
The Table.FromRecords() function is suitable for that sample data:
let
Source = Json.Document("[{""id"": 1, ""visitors"": 26, ""some_number"": 1, ""value"": 3500}, {""id"": 2, ""visitors"": 21, ""some_number"": 5, ""value"": 2000}]"),
AsTable = Table.FromRecords(Source)
in
AsTable
I have Excel Professional 2016 and I don't see the JSON option, but I can get to it via the "Other Sources" query option. Here are all the steps to convert a JSON array to a table.
Data > New Query > From Other Sources > From Web
Enter URL : "file:///C:/temp/document.json", (or a http web url) Press OK
A row is displayed with a "items" property and List type,
Click on "List", the items in list are displayed
Press "To Table" button in upper left corner, Press OK in next
dialog
A table with one column named "Column1" is displayed
Press the button next to the column name (has left and right arrows
on it)
Properties in the row object are selected
Uncheck "User Original column name as prefix", Press "OK"
Press "Close & Load" button in upper left corner
my file looks like
{
"items": [{
"code": "1",
"name": "first"
}, {
"code": "2",
"name": "second"
}, {
"code": "3",
"name": "third"
},
]
}
You need to convert the list to a table first, then you can expand the record column and proceed from there. If no luck, then you can take a look at this video I created recently for a similar question.

Best way to handle data list of REST web service with foreign key(one to many)

I am going to implement the REST base CRUD modal in my my app.I wan to display the list of product data with edit and delete link
Product
id, title, unit_id, product_type_id, currency_id,price
Q1: what should be json response look like?
There are two formats comes in my mind to place the data in Json as a response of REST Get call
[
{
id:1,
title:"T-Shirt",
unit_id:20,
unit_title: "abc"
product_type_id:30,
product_type_title:"xyz"
currency_id: 10,
currency_name: "USD"
min_price:20
},
{...}
]
and the another one is
[
{
id:1,
title:"T-Shirt",
unit: {
id: 20,
title: "abc"
},
product_type: {
id: 30,
title: "xyz"
},
currency_id: {
id:10,
name: "USD"
},
min_price:20
},
{...}
]
what is the better and standard way to handle the above scenario?
Furthermore, let suppose I have 10 more properties in product table which will never display on list page. but i needed it when user going to edit the specific item.
Q2: Should I the load all data once at the time of displaying product list and pass the data to edit component.
or
Load only the needed propeties of product table and pass the id to produt edit component and a new REST GET call with id to get the properties of product.
I am using React + Redux for my front end
Typically, you would create additional methods for API consumers to retrieve the values that populate the lists of currency, product_type and unit when editing in a UI.
I wouldn't return more data than necessary for an individual Product object.

cannot retain id of first table in left join

I am using sails waterline ORM and i have three tables in my model layer
1-s_class
attributes: {
c_title:{
type:'string',
required: true
},
sec:{
collection:'s_section',
via:"cls"
},
s_session:{
model:'s_session',
columnName:'session'
}
}
2-s_section
attributes: {
sec_title:{
type:'string'
},
sec_priority:{
type:'integer',
required: true
},
cls:{
collection:'s_class',
via:"sec"
}
}
3-s_form
attributes: {
studentName:{
type:'string'
},
s_class:{
columnName:'s_class',
model:'s_class'
},
s_section:{
columnName:'s_section',
model:'s_section'
}
}
i assigned both class and section to student which are saved in s_form table.when i write a query to get a student's record alongwith his class and section.something like this:
s_form.query("SELECT * FROM s_form LEFT OUTER JOIN s_class ON s_form.s_class=s_class.id LEFT OUTER JOIN s_section ON s_form.s_section=s_section.id",function(err,forms){
if(!err)
else{
res.json(forms);
}
});
it populates record of section and class but also affects auto increment primery key of s_form.actually this is because s_section and s_class also have default auto increment primery keys which after populating conflicts and in this case i got id of s_section.
i want to get id of s_form.is there any way to avoid this conflict and overriding of id without affecting default behavior of primery keys????
Note
s_form table contains custom columns means the columns mentioned above are static but it also contain columns which are created at runtime.that's why i can't use built in populate() query method nor i can specify column names like instead of select *.....
Based on your edited / updated post you I would query query to retrieve your column names prior to executing the query so that you can iterate over them and pass the table name as a prefix to each column name. This would allow you to avoid any conflicts.
You can use the following to get column names
SELECT *
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='yourdatabasename'
AND `TABLE_NAME`='yourtablename';
You can use this after your dynamic tables are created and save it in a variable so you don't have to keep doing it on every query.
Well, first you can have sails do this for you
s_form.find().populate('').populate('').exec(function(err,forms){/*....*/});
If you want to use query then you need to explicitly name your fields in order to avoid the conflict that will happen.
Instead of SELECT * FROM
You should specific each field so can rename the Id field to avoid these conflicts.
SELECT
s_class.c_title, s_class.id as classId,
s_section.sec_title,s_section.sec_priority,s_section.id as sectionId,
s_form.studentName,s_form.id as formId
FROM FROM s_form LEFT OUTER JOIN s_class ON s_form.s_class=s_class.id LEFT OUTER JOIN s_section ON s_form.s_section=s_section.id