Ember-table shows index on the header - ember.js

I am using ember-table but have a weird behavior. It automatically adds index next to my header title.
But after I click one of the header to sort the table, the index will disappear as I want. How do I get rid of the index in the first place. Plus, without the sorting function, the table was normal.
After I click anyone of the header to sort the column, the index will go away.
Here is my sort object
sorts = [
{ valuePath: 'username' },
{ valuePath: 'total_assignment_count' },
{ valuePath: 'accepted_assignment_count' },
{ valuePath: 'accepted_rate' },
{ valuePath: 'acl_name' },
{ valuePath: 'repo_name'}
];
template
<EmberTable as |t|>
<t.head
#columns={{this.tableColumns}}
#sorts={{this.sorts}}
#onUpdateSorts={{action (mut this.sorts)}}
/>
<t.body #rows={{this.tableData}} />
</EmberTable>

I found the answer.
Use only one sorting key.
sorts = [ { valuePath: 'username' } ];
Moreover, if you specify more than 1 key, then ember-table will help sort the table by the sequence.
EX:
sorts = [
{ valuePath: 'username' },
{ valuePath: 'score' },
];
The table will sort username first and then score

Related

Customized Reordering/Sorting of a List in Perl in O(n)

I am re-ordering a list.
My OrignalList, INPUT: #lineItems
[
{id=> 'id1', ..},
{id=> 'id2', 'groupId'=>45D,.. },
{id=> 'id3', 'groupId'=>56A, .. },
{id=> 'id4', 'groupId'=>45D, 'isParent'=>1 .. },
{id=> 'id5', ..},
{id=> 'id6', 'groupId'=>56A, 'isParent'=>1.. },
]
In above list, groupId signifies that the item is a part of bundle. GroupId uniquely determines the bundle group. If group Id is not present then its a non bundle item.
Aim - To re-order the list such that all the bundle items should be grouped together with parent item in the starting of every bundle and the incoming order of the bundle and non bundle items (when groupId not present) should remain unchanged.
To sort the list in O(n)
Expected Output:
[
{id=> 'id1', ..},
{id=> 'id4', 'groupId'=>45D, 'isParent'=>1 .. },
{id=> 'id2', 'groupId'=>45D,.. },
{id=> 'id6', 'groupId'=>56A, 'isParent'=>1.. },
{id=> 'id3', 'groupId'=>56A, .. },
{id=> 'id5', ..},
]
Here my Algo:
Create a sortedList of Ids = #sortedLineitemsIds
Use sortedIdsList to form the final sorted list
Code for #1
my $grouIdToLineItemIdMap;
foreach my $lineItem (#$lineItems) {
if(!$lineItem->{'groupID'}) { #non bundle item, add as it is
push #sortedLineitemsIds, $lineItem->{'id'};
} else {
if($lineItem->{'IsParent'} eq 1) {
unshift #{$grouIdToLineItemIdMap->{$groupId}}, $lineItem->{'id'};
} else {
push #{$grouIdToLineItemIdMap->{$groupId}}, $lineItem->{'id'};
}
}
}
push #sortedLineitemsIds, $grouIdToLineItemIdMap; # **[[Question 1]]** This will always add bundle items at the end irrespective of whether it was in starting or end.
Now this will yield sortedLineitemsIds =>
$VAR1 = [
'id1',
'id5',
{
'45D' => [
'id4:',
'id2:'
],
'56A' => [
'id6:',
'id3:'
]
}
];
Code for #2
foreach my $Id (#sortedLineitemsIds) {
if(determineIfSingleIdOrMapOfGroupId) { #**[[Question 2]]**
my $lineItem = grep #lineItems with $Id; #**[[Question 3]]**
push #sortedLineItems, $lineItem;
} else {
my $listOfLineItemsForGroupId = $sortedLineitemsIds->{$Id};
foreach groupLineItemId (#$listOfLineItemsForGroupId) {
my $lineItem = grep #lineItems with groupLineItemId; #**[[Question 3]]**
push #sortedLineItems, $lineItem;
}
}
}
I have now 3 questions marked above at different places in the code:
Question 1 -> Here I dont want to change the incoming order of
items. Just group them. But what I am doing is it is pushing all the
lineItems of the group in map, which I am appending at end after the
loop. How can I can do that in the loop to preserve that order?
Question 2 -> How can I determine whether it is a single Id (non
bundle id) or a groupID (basically a ref containing the
lineItemIds)?
Question 3 -> How can I grep the orginal list based on
the 'id' and get the corresponding lineItem?
You say you don't want to change the order of the items, but that's clearly not true. I'm going to assume you meant this:
I want to preserve the relative order of items which are either independent or the first of their group.
This can indeed be done in O(N).
We're going to build this:
my #grouped = (
[ $lineItem_id1 ],
[ $lineItem_id4, $lineItem_id2 ],
[ $lineItem_id6, $lineItem_id3 ],
[ $lineItem_id5 ],
);
To achieve that, we're going to use the following algorithm:
For each item,
If the item is independent,
Add it to #grouped.
Else,
Lookup if we've encountered the item's group before.
If the item is part of a group we haven't encountered before,
If it's the parent,
Add it to start of the existing group.
Else,
Add it to end of the existing group.
Else,
Create a new group from the item.
Add the new group to #grouped.
Add the new group to the lookup hash.
At the end of this, we'll end up with the following:
my $group_45D = [ $lineItem_id4, $lineItem_id2 ];
my $group_56A = [ $lineItem_id6, $lineItem_id3 ];
my %groups = (
'45D' => $group_45D,
'56A' => $group_56A,
);
my #grouped = (
[ $lineItem_id1 ],
$group_45D,
$group_56A,
[ $lineItem_id5 ],
);
Solution:
my #grouped;
{
my %groups;
for my $lineItem (#$lineItems) {
if ( my $groupId = $lineItem->{groupId} ) {
if (!$groups{$groupId}) {
push #grouped, $groups{$groupId} = [];
}
if ($lineItem->{isParent}) {
unshift #{ $groups{$groupId} }, $lineItem;
} else {
push #{ $groups{$groupId} }, $lineItem;
}
} else {
push #grouped, [ $lineItem ];
}
}
}
Finally, we simply need to flatten the list.
my #ordered = map { #$_ } #grouped;
Tested.

Azure Cosmos query to convert into List

This is my JSON data, which is stored into cosmos db
{
"id": "e064a694-8e1e-4660-a3ef-6b894e9414f7",
"Name": "Name",
"keyData": {
"Keys": [
"Government",
"Training",
"support"
]
}
}
Now I want to write a query to eliminate the keyData and get only the Keys (like below)
{
"userid": "e064a694-8e1e-4660-a3ef-6b894e9414f7",
"Name": "Name",
"Keys" :[
"Government",
"Training",
"support"
]
}
So far I tried the query like
SELECT c.id,k.Keys FROM c
JOIN k in c.keyPhraseBatchResult
Which is not working.
Update 1:
After trying with the Sajeetharan now I can able to get the result, but the issue it producing another JSON inside the Array.
Like
{
"id": "ee885fdc-9951-40e2-b1e7-8564003cd554",
"keys": [
{
"serving": "Government"
},
{
"serving": "Training"
},
{
"serving": "support"
}
]
}
Is there is any way that extracts only the Array without having key value pari again?
{
"userid": "e064a694-8e1e-4660-a3ef-6b894e9414f7",
"Name": "Name",
"Keys" :[
"Government",
"Training",
"support"
]
}
You could try this one,
SELECT C.id, ARRAY(SELECT VALUE serving FROM serving IN C.keyData.Keys) AS Keys FROM C
Please use cosmos db stored procedure to implement your desired format based on the #Sajeetharan's sql.
function sample() {
var collection = getContext().getCollection();
var isAccepted = collection.queryDocuments(
collection.getSelfLink(),
'SELECT C.id,ARRAY(SELECT serving FROM serving IN C.keyData.Keys) AS keys FROM C',
function (err, feed, options) {
if (err) throw err;
if (!feed || !feed.length) {
var response = getContext().getResponse();
response.setBody('no docs found');
}
else {
var response = getContext().getResponse();
var map = {};
for(var i=0;i<feed.length;i++){
var keyArray = feed[i].keys;
var array = [];
for(var j=0;j<keyArray.length;j++){
array.push(keyArray[j].serving)
}
feed[i].keys = array;
}
response.setBody(feed);
}
});
if (!isAccepted) throw new Error('The query was not accepted by the server.');
}
Output:

Deleting row using composite key

I have the table 'column_defn' with the following schema. The keys are column_name,database_name and table_name
column_name STRING(130) NOT NULL
database_name STRING(150) NOT NULL
table_name STRING(130) NOT NULL
column_description STRING(1000) NOT NULL
I am trying to delete a row using the following REST request
{
"session":"xxxxxxxxx"
"singleUseTransaction": {
"readWrite": {}
},
"mutations": [
{
"delete": {
"table": "column_defn",
"keySet": {
"keys": [
[
{
"column_name": "testd"
},
{
"table_name": "test atbd"
},
{
"database_name": "ASDFDFS"
}
]
]
}
}
}
]
}
but I keep getting the following error. Any idea as to where is wrong in the above request
{
"error": {
"code": 400,
"message": "Invalid value for column database_name in table column_defn: Expected STRING.",
"status": "FAILED_PRECONDITION"
}
}
Update: The following request seems to be successful. At least it was returning the success code 200 and the commitTimestamp. However, the row didn't get deleted
{
"singleUseTransaction": {
"readWrite": {}
},
"mutations": [
{
"delete": {
"table": "column_defn",
"keySet": {
"keys": [
[
"testd",
"dsafd",
"test atbd"
]
]
}
}
}
]
}
keys should contain an array-of-arrays. In the outer array, there will be one entry for each row you are trying to delete. Each inner array will be the ordered list of key-values that define a single row (order matters). So in your example, you want:
"keys": [["testd","ASDFDFS","test atbd"]]
Note that the original question is inconsistent in the true ordering of the keys in the table. The above answer assumes the primary key is defined something like:
PRIMARY KEY(column_name,database_name,table_name)

Rails, Highchart maps - adding custom data

I need some basic assistance with a Highmap (via Highcharts) I am trying to put in my Rails 4 app. I suspect I have some fundamental misunderstanding of it but can't find any clear guidance.
See a simple fiddle taken from the documentation, here
http://jsfiddle.net/SimonWalsh/zpdc1btu/
What I ultimately need to do is provide membership numbers for each country so that it will be displayed much the same as the population density is in this map.
I know I need to provide my data and the means to join it to the map data in
series : [{
data : data,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'code'],
name: 'Population density',
states: {
hover: {
color: '#BADA55'
}
}
}]
In this example, I am guessing that the data is being pulled from an external source and that the map data is the 'iso-a2' part of the array.
If this is the case, then why can't I supply this with my data....as an example see the added array with my data.....(just one example given for Denmark)
var mydata = [
{
"iso-a2": "dk",
"value": 30
},
]
and then do
series : [{
data : mydata,
mapData: Highcharts.maps['custom/world'],
joinBy: ['iso-a2', 'value'],
name: 'Population density',
states: {
hover: {
color: '#BADA55'
}
}
}]
This does not work.....any guidance at all (other than simply pointing me to docs would be greatly appreciated)
The joinBy specifies on which value you map a country with your data. With
joinBy: ['iso-a2', 'code']
you say that the 'iso-a2' value of the mapData should be equal to the 'code' value of your data. Therefore, your data must have this format:
var mydata = [
{
"code": "dk",
"value": 30
},
/* ... */
]

Filter duplicates in MongoDB C++

I am looking to find all duplicates in my collection by flagging duplicates based on the date. The following was my attempt but I am not sure how to use cmdResult within update. Any clues?
//filter duplicates
bson::bo cmdResult;
bool ok = c.runCommand(dbcol, BSON("distinct" << "date"), cmdResult);
c.update(dbcol,Query("date"<<cmdResult<<NOT<<"_id"), BSON("$set"<<BSON("noise"<<"true")), false, true);
The "distinct" command will return you a list of all unique "date" values there are in the collection. But what you need is a list of "date" values that occur more than once.
You can get this list using the aggregate command, by grouping by "date" and counting the entries, then matching for counts > 1:
aggregate([
{ $group: { "_id": "$name", count: {$sum:1} } },
{ $match: { $gt: [ count, 1 ] } }
])
You would then update your collection (multi:true) by querying for "date" IN that list, setting the "noise" field:
update( {"name": {$in: [<list>]} },{$set: {"noise": true} }, true, false )
For help on aggregation, see http://docs.mongodb.org/manual/reference/aggregation/