So I was trying to sort my some data in one of my sheets in ascending order automatically using google scripts. I created this script, and for some reason it does nothing.
function Filter() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Waitlist'),
range = sheet.getRange("A7:H");
range.sort(1);
}
Could someone take a look at this and give me some insight as to why the sort isn't working.
Try something like this:
function Filter() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sheet=ss.getSheetByName('Waitlist')
range=sheet.getRange("A7:H");
range.sort({column:1,ascending:true});
}
range.sort()
Related
I am trying to merge storefront filtering and sorting in my custom theme collections page in Shopify.
Both things work, but the 'sort_by' parameters are overwriting the filtering ones when these are multiple.
i.e of how the URL should look once filtering with two parameters (sizes XXS and XL) and sorting by ascending price:
../collections/new-arrivals?filter.v.option.size=XXS&filter.v.option.size=XL&sort_by=price-ascending
But this is what happens when sorting:
../collections/new-arrivals?filter.v.option.size=XXS&sort_by=price-ascending
Second filtering parameter gets overwritten by the sorting one.
Pasting below my code for the JS piece that triggers the sorting behaviour.
// sortby
$(function() {
Shopify.queryParams = {};
if(location.search.length) {
for(var aKeyValue, i = 0, aCouples = location.search.substr(1).split('&'); i < aCouples.length; i++) {
aKeyValue = aCouples[i].split('=');
if (aKeyValue.length > 1) {
Shopify.queryParams[decodeURIComponent(aKeyValue[0])] = decodeURIComponent(aKeyValue[1]);
}
}
}
document.querySelector('.sort-by').addEventListener('change', function(e) {
var value = e.currentTarget.value;
Shopify.queryParams.sort_by = value;
location.search = new URLSearchParams(Shopify.queryParams).toString();
});
})
Has someone ever tried to achieve something like this?
I would appreciate any help.
Thanks in advance,
How to remove custom records from any dimension. In the below case how do I filter only category 'S' and allow rest of them in dimension ?
Example
let data = [
{category:'A',value:10},
{category:'B',value:11},
{category:'S',value:12},
{category:'A',value:14},
{category:'B',value:12},
]
let ndx = crossfilter(data);
let dim= ndx.dimension(function(d){
if(d.category != "S") return d.category;
})
This above code runs into loop and the application crashes. I don't want to create separate data for this dimension rather link it with other cross filters.
I guess its pretty simple, I did little research after posting the question.
Just manipulate the group parameter being passed to the chart. The code goes something like this.
Since I am trying to remove the value by key lets first write a function for further uses as well.
function removeByKey(source_group, value) {
return {
all: function() {
return source_group.all().filter(function(d) {
return d.key != value;
});
}
};
}
Once this is done the place where you call the group method for the charts call this method. The first parameter of removeByKey method is the group itself the second is the key value which is supposed to be removed from the chart.
chart
.dimension(dimension_data)
.group(removeByKey(dimension_data_group, 'S'))
Thanks :)
I want to add to an array nested inside a table, appending a new item to the array.
But the returned run query is undefined. Please can anyone suggest a better way to run this?
rdb.table('SavedBaskets').get(basketId).run().then(function(result) {
let newPaymentHistory = [];
if ('paymentHistory' in result) {
newPaymentHistory = result.paymentHistory;
}
paymentHistory.push(charge);
return rdb.table('SavedBaskets').get(basketId).update({paymentHistory: newPaymentHistory}).run();
}).error(function(err) {
console.log(err);
});
You could use .append() such as
r.table("SavedBaskets").get(basketId).update(
{"paymentHistory": r.row("paymentHistory").append(charge)}
).run(conn)
https://www.rethinkdb.com/api/javascript/append/
Seen here
http://docs.rethinkdb.com/2.0/api/python/update/
r.db('dbname').table('urls').filter(function(url) {
return url("expires_at").date().eq(r.now().date())
.and(url("expires_at").hours().eq(r.now().hours().sub(1)))
});
I am trying to write the equivalent query using thinky ORM for node.js
I've never worked with Thinky, but according to docs, you should create model and make query on it.
1) Create model. I don't know what documents you are storing in Rethink. But something like this:
var thinky = require('thinky')();
var type = thinky.type;
// Create a model
var Urls = thinky.createModel("urls", {
id: String,
expires_at: Date
// another fields if needed
});
2) Query:
Don't know actual syntaxes for filter in Thinky, but somehting like this:
Urls.filter(function(url) {
return url("expires_at").date().eq(r.now().date())
.and(url("expires_at").hours().eq(r.now().hours().sub(1)))
}).then(function(result) {
// result is an array of instances of `Urls `
});
I have the view:
function (doc) {
var obj;
obj = {
one:doc.document.someParameter1,
two:doc.document.someParameter2
};
emit(doc.document.id, obj);}
On request it returns several something like
{"total_rows":511,"offset":381,"rows":[
{"id":"CDOC_2.16.840.1.113883.3.59.3:0947___QCPR___80717","key":"7012979","value":{"one":"one","two":"two"}},
{"id":"CDOC_2.16.840.1.113883.3.59.3:0947___QCPR___80921","key":"7012979","value":{"one":"one","two":"two"}}
]}
Is there a way instead of several results get just one?
Of course, I could do filtering on the application side, but this could be very expensive since I have to transfer all unnecessary results.