Creating dropdown and populating unique value in Vue js - vue.js

I am very new to Vue js. We are displaying a table on UI having 4 columns as
S.No | Column | Description | Type
We need to list all the unique value in Type in a drop-down (describing the datatype of a column), I am able to make Type as a drop-down however struggling to get the list of unique values in Type.
I am getting all data in an Array [sno:(..), column:(..), description:(..), type:(..)] and I am trying to get to type to put the value in one of the array and the taking unique value from that.
The code I tried first is
this.columnType = this.columnData.filter(data => {return data.type.toUpperCase()});
Also, I tried the following but it is just filtering on the specific datatype in this case "Timestamp"
this.columnType = this.columnData.filter(function(data) {
return data.type.toUpperCase() == "TIMESTAMP_NTZ"
});
Looking for some guidance to get this right.
Thanks in advance to all for helping

Use the following computed property to get the list of unique Type values:
computed:
{
onlyTypes()
{
// we want an Array with all the Type values
return this.tableDataRows.map(dataItem => dataItem.type);
},
uniqueTypes()
{
// we want only the unique Type values
return this.onlyTypes.filter((value, index, self) => self.indexOf(value) === index);
}
}

Related

How to update an certain row value using gota dataframe?

I'm trying to parse data from certain server, and need to export it to excel or csv.
before I export, I need to do some post processing such as merging values between parsed data.
for example,
There are two series out of all data.
series#1 - {Name: "MATH", Student:"Zay",Id:"MATH-123", Date:"12/25/2022", Status:"Good"}
series#2 - {Name: "MATH", Student:"Zay",Id:"MATH-124", Date:"12/26/2022", Status:"Bad"}
What I want to do is,
I want to update series#1's Status to
{Name: "MATH", Student:"Zay", Id:"MATH-123,MATH-124", Date:"12/25/2022,12/26/2022", Status:"Bad"}
Id, Date ==> combining with ","
Status ==> changing to latest result
Now I'm using Filter method of DataFrames,
type MyDataSet struct{
Name string
Student string
Id string
Date string
Status string
}
totalDF:=series1_result //overall result dataframe
df := dataframe.LoadStructs(series2_result) //new dataframe which needs to be compared to previous data `totalDF`
length := df.Nrow()
for i:=0;i<length;i++ {
name:=df.Subset(i).Col("Name")
student:=df.Subset(i).Col("Student")
query:= totalDF.Filter(
dataframe.F {
Colname:"Name",
Comparator:series.Eq,
Comparando:name,
},
).Filter(
dataframe.F {
Colname:"Student",
Comparator:series.Eq,
Comparando:student,
}
)
if query.Nrow()==0 {
totalDF = totalDF.Concat(df.Subset(i))
} else {
newDF:= dataframe.LoadStructs([]MyDataSet{
{
Name:query.Col("Name").String(),
Student:query.Col("Student").String(),
Id:query.Col("Id").String()+","+df.Subset(i).Col("Id").String(),
Date:query.Col("Date").String()+","+df.Subset(i).Col("Date").String(),
Status:df.Subset(i).Col("Status").String(),
}
})
query.Set(
series.Ints([]int{0}, newDF) //It's not updated as query was not an pointer
)
}
}
Even though I updated values on result of query, it's not updated on totalDF
How can I query the data from totalDF and update the data on that totalDF?
How can I get index number of Filtered item using Filter function?
Should I implement search function instead of using Filter function?
I would really appreciate it if you could help me.
Thanks everyone!
Merry Christmas!
*I tried to find out from official docs.
*But every method returns Value, not Pointer.

how can i filter a array in Vue3

I am new to Vue3.
I have to filter a array with same item and push results into another array
My array is
let list = [
{"name":"1000","properties":{"item":"1","unit":"DZN"}},
{"name":"2000","properties":{"item":"1","unit":"CTN"}},
{"name":"3000","properties":{"item":"2","unit":"DZN"}},
{"name":"4000","properties":{"item":"3","unit":"CTN"}}
]
I need corresponding name with condition item =1 in another array.
Result array will be similar to [{"name":"1000", "unit":"DZN"}, {"name":"2000", "unit":"CTN"}]
TIA
If I understand correctly you want to create an array of objects with name and unit attributes from records which have item values equal to 1. To do that you have to first filter an array to get only records which have desired value of item and then map those values to create a new array of objects.
Here is an example:
let list = [
{"name":"1000","properties":{"item":"1","unit":"DZN"}},
{"name":"2000","properties":{"item":"1","unit":"CTN"}},
{"name":"3000","properties":{"item":"2","unit":"DZN"}},
{"name":"4000","properties":{"item":"3","unit":"CTN"}}
]
const filteredList = list.filter((e) => e.properties.item === "1").map((e) => { return {name: e.name, unit: e.properties.unit}});
console.log(filteredList);
If this is a Vue3 reactive variable remember to add .value before filter() method to make it work

Can I update a FaunaDB document without knowing its ID?

FaunaDB's documentation covers how to update a document, but their example assumes that I'll have the id to pass into Ref:
Ref(schema_ref, id)
client.query(
q.Update(
q.Ref(q.Collection('posts'), '192903209792046592'),
{ data: { text: "Example" },
)
)
However, I'm wondering if it's possible to update a document without knowing its id. For instance, if I have a collection of users, can I find a user by their email, and then update their record? I've tried this, but Fauna returns a 400 (Database Ref expected, String provided):
client
.query(
q.Update(
q.Match(
q.Index("users_by_email", "me#example.com")
),
{ name: "Em" }
)
)
Although Bens comments are correct, (that's the way you do it), I wanted to note that the error you are receiving is because you are missing a bracket here: "users_by_email"), "me#example.com"
The error is logical if you know that Index takes an optional database reference as second argument.
To clarify what Ben said:
If you do this you'll get another error:
Update(
Match(
Index("accounts_by_email"), "test#test.com"
),
{ data: { email: "test2#test.com"} }
)
Since Match could potentially return more then one element. It returns a set of references called a SetRef. Think of setrefs as lists that are not materialized yet. If you are certain there is only one match for that e-mail (e.g. if you set a uniqueness constraint) you can materialize it using Paginate or Get:
Get:
Update(
Select(['ref'], Get(Match(
Index("accounts_by_email"), "test#test.com"
))),
{ data: { email: 'test2#test.com'} }
)
The Get returns the complete document, we need to specify that we require the ref with Select(['ref']..
Paginate:
Update(
Select(['data', 0],
Paginate(Match(
Index("accounts_by_email"), "test#test.com"
))
),
{ data: { email: "testchanged#test.com"} }
)
You are very close! Update does require a ref. You can get one via your index though. Assuming your index has a default values setting (i.e. paging a match returns a page of refs) and you are confident that the there is a single match or the first match is the one you want then you can do Select(["ref"], Get(Match(Index("users_by_email"), "me#example.com"))) to transform your set ref to a document ref. This can then be passed into update (or to any other function that wants a document ref, like Delete).

Filter other columns based on first columns

I'm using jquery data tables and I'm assigning an array of values to the initialization of the data table. The table basically looks like this.
based on an an radio button I would like to limit the items that are display in the table and the items that are searched in the table.
For my example it would be based on the "Chart column". I want to limit the table to only show the items that are based on chart "D" or Chart "S". Here is how I'm initializing the table.
if (!$.fn.DataTable.isDataTable( '#fundLookUptbl' ) ) {
fundTable = $('#fundLookUptbl').DataTable( {
data: funds,
columns: [
{ "mData": "chart" },
{ "mData": "fund" },
{ "mData": "orgDefault" },
{ "mData": "progDefault" }
]
} );
var filteredData = fundTable
.columns( [0, 1] )
.data()
.eq( 0 )
.filter( function ( value, index ) {
return value = 'D' ? true : false;
} );
}
This is obviously not working, and the filterData variable is a lousy attempt on trying to make it work. I'm having a hard time understanding the API's. So the question is , How can initialize the table to only show the items that are based on a given chart. I know that I can remove the items of the array but i don't want to do that since I would simple like to be able to switch between chart "D" and "S" but still continue to search through the other columns.
I believe that filtering the column would solve your problem.
table.column(0).search('Bruno').draw()
So you could just filter the column when the radio button selection change
Here is a fiddle example
I´m not sure to be understanding what you want to do but here are some options:
One way is selecting by default value example "s". You can use a dropdown is easier to handled .Then select with jQuery the dafault value "s" on that dropdown and add a function
$("#DropdownId").change(function () {
var chart=$("#DropdownId").val();
});
$.ajax({
url: "url")",//url to reload page with new value
type: "POST",
data: {chart:chart},
success: function (data) {
}
});
});
on this way the filter is on backend. If you want to do something on the row depending of a column value you shoud to add something like this
"fnRowCallback": function (nRow, mData, iDisplayIndex, iDisplayIndexFull) {
if (mData["chart"] =="s") {
return nRow;
}
},
Datatables: custom function inside of fnRowCallback.
Good luck
fundTable.order( [0, 'asc'] );
Try that or look at this particular page for reference:
https://datatables.net/reference/api/order%28%29
Basically orders in pair of columnIndex in either asc(ending) or desc(ending) order.

Logstash condition to check if message contains any of from list of string

I have a javastack trace in message field and an array field having list of string like ["NullPointer", "TimeOutException"].
I want a conditional check on message field such that it checks if message contains any of from list of string.
Any idea how to get this?
It's a bit of a hack, but check out the translate{} filter. You could define your fields to translate to "1" (true, etc), with a default of "0". Then check that value to determine if it was in the set.
EDIT: for those who don't like to fish:
filter {
translate {
field => myInputField
dictionary => [
"NullPointer", 1,
"TimeOutException", 1
]
fallback => 0
destination => myOutputField
}
if [myOutputField] == "1" {
# it contained one of the items in the dictionary
...
}
else {
# it did not contain one of the items in the dictionary
...
}
}