Reverse sort data in Google Sheet - forms

Google Forms linked to Google Sheets record submissions oldest to newest. We must scroll to the bottom of the sheet for the newest submission. I'd like to reverse that behavior so the newest submissions are at the top and oldest at the bottom. What is the best way to do this?

Try (put a trigger on onFormSubmit)
function onFormSubmit(e) {
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getActiveRange().getRow();
var column = e.values.length + 1;
var range = sheet.getRange(2, 1, row-1, column);
range.sort({column: 1, ascending: false});
}

Related

Make TODAY formula stop when checkbox is clicked

I'm setting up a Google Sheet with a few columns to be filled for a certain request. So, I included a checkbox to be clicked at the end as a confirmation the request is done. My idea is to have an automated column called 'Request Date' automatically filled with the current date as soon as the Confirmation checkbox is clicked. However, can't use TODAY() formula once it's going to change the date every day. Any solution for this?
unfortunately no. you can't stop TODAY on demand by any means without a script. but you could have a script which would print out the date if certain checkboxes were checked.
function onEdit(e) {
var aCell = e.source.getActiveCell(), col = aCell.getColumn();
if(col == 5) { //number of column where you have a checkbox
var adjacentCell = aCell.offset(0,1);
var newDate = Utilities.formatDate(new Date(),
"GMT+1", "dd/MM/yyyy");
adjacentCell.setValue(newDate);
}}
this will print date in column F if a checkbox in column E is checked
or perhaps like this:
function onEdit(e) {
var activeSheet = e.source.getActiveSheet();
if (activeSheet.getName() == "Sheet1") { // SHEET NAME
var aCell = e.source.getActiveCell(), col = aCell.getColumn();
if (col == 12) { // COLUMN WITH CHECKBOXES
var dateCell = aCell.offset(0,1); // OFFSET ROWS, COLUMNS
if (aCell.getValue() === true) { // VALUE OF CHECKED CHECKBOX
var newDate = new Date();
dateCell.setValue(newDate);
} else {
dateCell.setValue("");
}}}}

How to add row selection checkbox for ag-grid

Is there a way to have row selection checkbox for each row without configuring a special column for it? I mean to add propertie for my gridOptions and to see checkbox near each row, then to get all selected rows?
All the documentation I read is showing how to do it by adding it to specific column.
Thanks,
You can still have row selection without having a checkbox column - you can either simply have selection based on row selection, or have a column render with a checkbox in it (with a custom cell renderer).
Take a look at the Selection Documentation for more information about row selection, and at the Cell Rendering Documentation about cell rendering
I know it is too late to answer on this post. But It may help someone who look for solution still. It works with checkbox selection on each row (click anywhere on the row to select checkbox), shift/control and toggle selection. Here I have given only necessary code.
vm.gridOptions = {
appSpecific : {},
onRowClicked : onRowClicked,
onGridReady : function() {
let api = vm.gridApi = vm.gridOptions.api;
}
};
function toggleSelect(row) {
row.node.setSelected(!row.node.isSelected(), false);
}
function onRowClicked(row) {
var appSpecific = vm.gridOptions.appSpecific;
var lastSelectedRow = appSpecific.lastSelectedRow;
var shiftKey = row.event.shiftKey;
// if not modifier keys are clicked toggle row
if (!shiftKey) {
toggleSelect(row);
} else if (lastSelectedRow !== undefined) {
if (shiftKey) {
var startIndex, endIndex;
// Get our start and end indexes correct
if (row.rowIndex < lastSelectedRow.rowIndex) {
startIndex = row.rowIndex;
endIndex = lastSelectedRow.rowIndex;
}
else {
startIndex = lastSelectedRow.rowIndex;
endIndex = row.rowIndex;
}
// Select all the rows between the previously selected row and the
// newly clicked row
for (var i = startIndex; i <= endIndex; i++) {
vm.gridApi.selectIndex(i, true, true);
}
}
}
// Store the recently clicked row for future use
appSpecific.lastSelectedRow = row;
getSelection(); // Implement functionality to get selected rows
}

JQuery Isotope Combination Filter - preselection

I try to implement an Isotope combination filter. One of the three filters should be set to one selection, the other two filters should show all the items according to these filters. Everything works fine with one exception: When clicking the first time, the preselection is "lost" and all the items according to the preselected filter are shown. Only after the preselected filter is clicked, everything works.
As I am a beginner, I have no idea how to this. Any ideas how to solve this?
Thanks a lot!
<script>
$('#container').isotope({ filter: '.current' });
$(function(){
var $container = $('#container'), filters = {};
$container.isotope({
itemSelector : '.prod'
});
// filter buttons
$('.filter a').click(function(){
var $this = $(this);
// don't proceed if already selected
if ( $this.hasClass('selected') ) {
return;
}
var $optionSet = $this.parents('.option-set');
// change selected class
$optionSet.find('.selected').removeClass('selected');
$this.addClass('selected');
// store filter value in object
// i.e. filters.color = 'red'
var group = $optionSet.attr('data-filter-group');
filters[ group ] = $this.attr('data-filter-value');
// convert object into array
var isoFilters = [];
for ( var prop in filters ) {
isoFilters.push( filters[ prop ] )
}
var selector = isoFilters.join('');
$container.isotope({ filter: selector });
return false;
});
});
I had the same problem. The only solution I found was simulating a click on the button for that specific selection after page load.
This is possible with jQuery.
Set an ID for the button in question and call:
$("#button_id").click();

Slick grid set value on autocomplete cell

I'm trying to set values in a slick grid from jQuery thru val and text e.g. .find('div.slick-cell.l2.r2').text('xyz'). There is a jquery autocomplete on the cell in question but it only gets activated on click. So when I click the cell in question it get overwritten by the initial defaultValue in the editor:
function ComboBoxEditor(args) {
...
this.loadValue = function (item) {
defaultValue = item[args.column.field] || "";
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
...
Can I get the jQuery text value from within the world of the slick grid.
Think of slickgrid as a rendering engine and dataView as the data interface (You are using dataView right?) Jquery or javascript editing of dom elements isn't gong to work so think about how jquery/javascript can use the dataView methods to do the updating.
I ran into this same issue when adding drag and drop of files into SlickGrid
I detect the elementID of the drop and map it back to the dataView row and column.
Here is the function I used for text pasting:
function insertText(textString, location) {
grid.resetActiveCell();
$(location).click();
var startCell = grid.getActiveCell();
if (startCell) {
// only paste text into active cells for now
var columnDef = grid.getColumns();
var colField = columnDef[startCell.cell].field;
if (!dataView.getItem(startCell.row)) {
// new row
var tobj = {'id': "new_" + (Math.random() + 1).toString(36).substring(7)};
tobj[colField] = textString;
dataView.addItem(tobj);
} else {
// modify existing cell
var item = dataView.getItem(startCell.row);
item[colField] = textString;
dataView.updateItem(item.id, item);
}
grid.resetActiveCell();
grid.render();
dataView.refresh();
}
}

Titanium iPhone: making a dialog similar to this standard iPhone ui?

I'm attempting to implement a dialog for a user to choose several of many toggle-able options. The iPhone has a nice model for this, in Settings/General/Keyboards:
However, I could not re-create this exactly: this task is to show two table sections (tables?), but only one is editable. (The one with the keyboard list.)
The Titanium API only allows a table to be editable, not a section. And I couldn't figure out how to layout two tables to scroll together. (I tried putting them both in a ScrollView, etc.)
Anyone able to do something like this?
EDIT: Here's my workaround, which I consider sub-optimal. :-( Instead of that second table section with the control element, I'm using a toolbar at the bottom:
You can control whether any row is editable or not by setting the editable property on the row (it defaults to the value of the table if not set).
You don't need two tables; one table view, set to grouped, with separate sections will suffice. That way scrolling works perfectly, and editing works across the entire table. I'm not sure why editing is only working for one section for you, but I've put together an example which shows editing working across multiple table sections. To run it, create a project and replace the content of app.js with the following:
// Windows
var root = Ti.UI.createWindow();
var window = Ti.UI.createWindow({
title: 'Keyboards',
showNavBar: true
});
// Create table
var table = Ti.UI.createTableView({
editable: true,
style: Ti.UI.iPhone.TableViewStyle.GROUPED
});
// Create section 1 - this section is editable
var section1 = Ti.UI.createTableViewSection();
var row1 = Ti.UI.createTableViewRow({title:"English (UK)"});
var row2 = Ti.UI.createTableViewRow({title:"Chinese - Simplified"});
section1.add(row1);
section1.add(row2);
// Create section 2 - this section is not editable
var section2 = Ti.UI.createTableViewSection();
var row3 = Ti.UI.createTableViewRow({title:"French", editable: false});
var row4 = Ti.UI.createTableViewRow({title:"Spanish", editable: false});
section2.add(row3);
section2.add(row4);
// Add data to the table
var data = [
section1,
section2
];
table.data = data;
window.add(table);
// Set up the buttons
var edit = Titanium.UI.createButton({
title:'Edit'
});
edit.addEventListener('click', function()
{
window.setRightNavButton(cancel);
table.editing = true;
});
var cancel = Titanium.UI.createButton({
title:'Cancel',
style:Titanium.UI.iPhone.SystemButtonStyle.DONE
});
cancel.addEventListener('click', function()
{
window.setRightNavButton(edit);
table.editing = false;
});
window.setRightNavButton(edit);
// Add the window to the nav view and open
var nav = Ti.UI.iPhone.createNavigationGroup({
window: window
});
root.add(nav);
root.open();