get values of select option in angular 4+ - node.js

Hi I have a question how to get the values from list in a select option.
I have this array
{
"C_ID": "Item044",
"Descripcion": "Item 1",
"ID": "044"
},
{
"C_ID": "Item045",
"Descripcion": "Item 2 ,
"ID": "045"
},
{
"C_ID": "Item046",
"Descripcion": "Item 4",
"ID": "046"
},
{
"C_ID": "Item047",
"Descripcion": "Item 5",
"ID": "047"
},
and I get this values in a select option with NgFor but I need when selected for example Item 1 get the ID and C_ID in a input text automatic

and I get this values in a select option with NgFor but I need when selected for example Item 1 get the ID and C_ID in a input text automatic
Wire an ng model to the select input. And then wire the backed field to the input. Now when the select changes the input text should change.

Related

CosmosDB accent (diacritics) insensitive query

How do I query CosmosDB ignoring accents?
Example:
{"id": "1", "name": "Émpresa 1" }
{"id": "2", "name": "empresa 2" }
SELECT *
FROM container_name
WHERE name LIKE 'empresa%'
I want to retrieve both records from this query, how can I do that?
If it's not possible "out of the box" then is there any workaround?
Cosmos DB will save data in the specified encoding of your text. As 'É' and 'e' are not the same, I believe you have two options:
1- Replace special chars to it's root form: https://stackoverflow.com/a/2086575/1384539
2- Use a Search Engine (e.g. Azure Cognitive Search) which will to the previous work for you
What you need here is just '%mpresa%' as the first item has starting letter with 'E' while second one has 'e'
SELECT * FROM c WHERE c.name LIKE "%mpresa%"
Demo
[
{
"ItemId": "1",
"name": "Émpresa 1",
"id": "c599d43a-a88b-441f-b6df-361380f05eac",
},
{
"ItemId": "2",
"name": "empresa 2",
"id": "ed894a28-f439-4a23-88e2-80d29ff106e0",
}
]
If you want to perform free text search you may consider the feature supported for SQL API with Azure cognitive search here

Cosmos DB - Efficient query to find list of items in an array?

Consider the following documents:
{
"id": "0001",
"name": "product 1",
"description": "product 1 description",
"categories": ["category1", "category2"]
}
{
"id": "0002",
"name": "product 2",
"description": "product 2 description",
"categories": ["category2", "category3"]
}
{
"id": "0003",
"name": "product 3",
"description": "product 1 description",
"categories": ["category1", "category4"]
}
What I want to do is find the products where the product category could be category2 or category3.
To fetch this, I wrote the following query:
Select * from Root r where
exists(select value c from c in r.categories where c in ("category2", "category3"))
The query above works well and gives me the desired results.
What I am wondering is if this query can be improved?
array_contains looks for a single item in an array, the item you are looking for is the second argument. So you need:
select *
from c
where array_contains(c.categories, "category2")
or array_contains(c.categories, "category3")
And then look at the performance.

Tabulator - rowContextMenu - HowTo get which cell the mouse-rightclick is performed

Is it possible to get which cell the right-click context menu is performed with rowContextMenu?
rowContextMenu gives the data for all cells in the row, but I have not found how to get which cell the action happens.
Using contextMenu could be an option, but I want to build the columns-setup serverside as json and load the columns with
table.setColumns(columnsJson)
Setting columns contextmenu as a function is not a valid json,
columns": [
{ "title": "", "field": "age", "sorter": "string", "headerSort": false, "contextMenu": cellContextMenu}
]
And setting the "contextMenu" as a "string" fails with: error: "Uncaught TypeError: o.forEach is not a function"
columns": [
{ "title": "", "field": "age", "sorter": "string", "headerSort": false, "contextMenu": "cellContextMenu"}
]
Any tips on getting which cell the menu is trigged with rowContextMenu?
Or is there maybe a different/better solution builtin in Tabulator?
Reason for building the column setup serverside is that I want to have different context menu based on type of cell-data, and it will vary based on selection by user.
BR
Bjorn
If you want to get the cell that is being clicked on then you need to use the Cell Context Menu instead as this is passed the cell component that has been clicked.
You would then need to assign the menu per cell but this is easy if you define it as an array outside the table and then reference it on each column definition using the contextMenu property:
//define cell context menu
var cellContextMenu = [
{
label:"Reset Value",
action:function(e, cell){
cell.setValue("");
}
},
]
//add header menu in column definition
var table = new Tabulator("#example-table", {
columns:[
{title:"Name", field:"name",contextMenu:cellContextMenu},
{title:"Age", field:"age",contextMenu:cellContextMenu},
{title:"Address", field:"address",contextMenu:cellContextMenu},
]
});

Parameter whole range or table in Excel Power Query

I have an Excel sheet with a column containing IDs of items I want to retrieve
||ID||
|123|
|124|
|125|
The API I am calling can take an array of IDs as input (e.g. https://API.com/rest/items?ID=123&ID=124&ID=125....(up to 50))
and returns one JSON.
"data": [
{
"id": 123,
"fields": {
"name": "blah blah",
"description": "some description",
}
},
{
"id": 124,
"fields": {
"name": "blah bli",
"description": "some description",
}
},
{
"id": 125,
"fields": {
"name": "blah blo",
"description": "some description",
}
},...
]
}
I would like to load data from this JSON in another table or sheet.
||ID||Name||
|123|blah blah|
|124|blahblo|
|125|blahbli|
I would know how to parameterise the query by referencing single cells, but if I am retrieving 100+ items, that's a lot of work.
Can't I somehow build a query that gets each value (ID) from the table or range in one simple move?
--edit1--
Found another API endpoint where I can provide an array of IDs. (before I thought it was only possible to send one ID per request to retrieve one JSON at a time)
--edit2--
Maybe I can concatenate all IDs into the request URL already in an Excel cell and parameterise just based on that one cell. (still experimenting)
If you've got the JSON for each ID, then you just need to pull out the name part.
For example, if you have a column [JSON] with the JSON for each ID, then you can create a custom column using Json.Document([JSON])[data][name] as the formula.
You can likely combine pulling the JSON and parsing it into a single step if you'd like.

node.js and postgresql UPDATE nested JSON key

I have a table called "json" in my database, with 2 columns: "id" and "data"
Only one row is stored inside it at the moment, having 1 as id and a JSON structure as data:
{
"elements": {
"nodes": [
{
"data": {
"id": "n0",
"name": "Name here",
"color": "#FFFFFF"
}
},
{
"bob": "hello"
}
]
}
}
I need to update a key of the json: "Name here" has to become "updated"
This is what I tried:
db.query("UPDATE json SET $1 WHERE data->'elements'->'nodes'->0->'data'->'name'=$2", ['updated', 'Name here'])
but I get an error:
syntax error at or near "'updated'"
When using the Postgres JSON navigators it's important to terminate your chain with the text retrieval navigator ->> if you want to do comparisons like that:
UPDATE json SET $1 WHERE data->'elements'->'nodes'->0->'data'->>'name'=$2
That should permit comparing text to text instead of json.
I think you might also be able to use #>> to dig the whole way down in one shot:
UPDATE json SET $1 WHERE data#>>'{elements,nodes,0,data,name}'=$2

Resources