How to apply filters in Googlesheet API using Java - api

I have an API built along with Google Sheet API which interact with my google sheet and returns all the data. Is there a possible way to apply filter in google sheet and get only the data available to the filter(As like how we do filter in google sheet manually)?

You may check the following:
DataFilter that describes what data should be selected or returned from a request.
{
// Union field filter can be only one of the following:
"developerMetadataLookup": {
object(DeveloperMetadataLookup)
},
"a1Range": string,
"gridRange": {
object(GridRange)
},
// End of list of possible types for union field filter.
}
FilterCriteria for showing/hiding rows in a filter or filter view.
{
"hiddenValues": [
string
],
"condition": {
object(BooleanCondition)
},
}
PivotFilterCriteria for showing/hiding rows in a pivot table.
{
"visibleValues": [
string
],
}
Hope this helps!

Related

Google Sheets API Chart - change a given datapoint fillcolor

In Google Sheets API, when using a chart shape, how can I colour a given datapoint a custom RGB? In the image below I have changed the color of 3 random datapoints. Is this possible?
It is possible to change the color and use a custom RGB color. If you already have the chart created, all you need to do is to use the batchUpdate method, and when creating the request include updateChartSpecRequest, then you'll need to select the type of chart that you are updating. In your case, based on the screenshot it would be basicChart, then from the chart, you want to update the series since those are the ones that generate the columns, and you can modify the color parameter there according to the official documentation.
Depending on what you want to end up doing, the structure of the request may end up being similar to this:
Request:
'request' : [
{
"updateChartSpec": {
"chartId": integer,
"spec": {
"basicChart": {
"series": [
{
"color": {
{
"red": number,
"green": number,
"blue": number,
"alpha": number
}
},
}
]
},
}
},
}
]
Note:
If you want to do it upon creation, instead of using updateChartSpec you would want to use addChart.
References:
updateChartSpecRequest
Color
BasicChartSeries
BasicChartSpec
addChart

Can we create multiple sheets using Google Sheet API the way we create manually?

I want to add multiple sheets with different values under a google sheet but I cannot find it anywhere. Is it possible?
Your question is quite unclear. In case you're looking for a python way of adding new sheets, then you can refer to google sheets API documentation to Add sheets. You may use the Batch Update and Add Sheet request
{
"requests": [
{
"addSheet": {
"properties": {
"title": <<Your Sheet Name Goes Here>>,
"gridProperties": {
"rowCount": 20,
"columnCount": 12
},
"tabColor": {
"red": 1.0,
"green": 0.3,
"blue": 0.4
}
}
}
}
]
}

How can I Group Rows via the Google Sheets API?

I'm looking for a way to create a group of rows via the Google Sheets API - is there a way to do this? I can't see to find an API that will do this, but it seems like it should be a fairly common formatting need.
This feature is supported in the UI by selecting a set of rows, right clicking and the option pops up to create a group, see the screenshot linked below. I'm just looking for a way to do that via an API.
Use this --> Range.shiftColumnGroupDepth
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var range = sheet.getActiveRange();
// The column grouping depth is increased by 1.
range.shiftColumnGroupDepth(1);
// The column grouping depth is decreased by 1.
range.shiftColumnGroupDepth(-1);
You can accomplish this through version 4 of the Google Sheets API.
You will need to submit an HTTP POST to this endpoint:
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}:batchUpdate
You will need to pass a valid JSON request. I created a simple spreadsheet with some rows to group and used this JSON as a test to group rows 14-17:
{
"requests": [
{
"addDimensionGroup": {
"range": {
"dimension": "ROWS",
"sheetId": 0,
"startIndex": 14,
"endIndex": 17
}
}
}
]
}
Note that the startIndex is the row (or column) number that everything will fold into and will remain visible even if you collapse the group, while endIndex is the last element of the group which will remain hidden when the group is collapsed.
The documentation for this is here. If your window is wide enough it will show a "Try this API" pane on the right side. You can enter the spreadsheetId of your sheet and build up the JSON request body and test it to see it work directly on a sheet - if you have it open in another window you should see the update happen almost immediate after you click the "Execute" button.
Creating Column and Row Groups
Column Groups
function createSomeColumGroups() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName("Sheet189");//this is used in the request
var resource='{"requests": [';
for(var i=1;i<25;i+=3) {//start at column 1 and ends at 24 making them in groups of 3
if(i>1){resource+=', ';}
resource+=Utilities.formatString('{"addDimensionGroup": {"range": {"dimension": "COLUMNS","sheetId": %s,"startIndex": %s ,"endIndex": %s}}}',sh.getSheetId(),i,i+2);
}
resource+=']}';
Logger.log(resource);
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
}
Row Groups
function createSomeRowGroups() {
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName("Sheet189");
var resource='{"requests": [';
for(var i=1;i<25;i+=3) {
if(i>1){resource+=', ';}
resource+=Utilities.formatString('{"addDimensionGroup": {"range": {"dimension": "ROWS","sheetId": %s,"startIndex": %s ,"endIndex": %s}}}',sh.getSheetId(),i,i+2);
}
resource+=']}';
Logger.log(resource);
Sheets.Spreadsheets.batchUpdate(resource, ss.getId());
}
Don't forget to go the Advanced Google Services and enable Sheets API version 4 and you will also have to enable on the Google Cloud Platform

Not getting results field after querying task by ID in Lookback API

I'm trying to query tasks by ObjectID to get their most recent snapshots. I'm trying the API out, and am not getting the expected results that I was hoping for after reading the docs. I don't get a results field in the response object. Here's my code:
_loadTaskSnapshot: function() {
let snapshot = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: '/workspace/2290039850'
},
"find": {
"ObjectID": 34858774310,
"_ValidFrom": {
"$gte": "2016",
"$lt": "2017"
}
},
"fields": ["Name", "Estimate", "ToDo", "TimeSpent"],
});
return snapshot.load();
}
This is the store with 18 snapshots for the specified task. The first snapshot is opened. You can see there is no results field where I could find the Name, Estimate, ToDo, and TimeSpent:
Alejandro, you are asking for the changes in the fields, not the values of the fields. This is a common misconception with the lookback api. There is a special way to get the current values shown in the help pages available inside Agile Central.
Any information returned is actually held within the object underneath 'raw' and 'data'. Each of those may not contain any values if there has been no 'changes' to those fields at the time the snapshot was taken.

Can I show data is sorted when not sorted by dataTables

I am using the https://datatables.net/ jQuery plugin to display client side tabular data.
The data for my table is pre-sorted so I don't want the overhead of dataTables doing the first sort. I have set aaSorting to [] so that dataTables does not sort the data.
My problem is that I would like the header style to show which column the data is sorted by and when that column is sorted for it to toggle the sort order.
I tried a cheat of the following which displays the way I want but I have to click twice to change the search to descending.
dataTableOptions.fnInitComplete = function (oSettings, json) {
$table.find('th:first').addClass('sorting_asc');
};
Any suggestions would be greatly appreciated.
Thanks.
You can set the default sort direction of your target column to 'desc' by using asSort as documented here. This would sort your table in descending order on the first click. You would still to set the class of th:first to sorting_asc on init.
// Using aoColumns
$(document).ready( function() {
$('#example').dataTable( {
"aaSorting": [],
"aoColumns": [
{ "asSorting": [ "desc", "asc" ] }, // assumes you are targeting column 1
...// other columns
],
...// other configuration
} );
} );