i have a jqxgrid with a dropdown column. Now, if in a row a dropdown item is selected, this dropdown item should be deactivated in all following rows.
So, first i have to get all rows:
var rows = $('#jqxgridpop').jqxGrid('getboundrows');
then get all cells containing the dropdown
for (var i = 0; i < rows.length; i++) {
var cell = $('#jqxgridpop').jqxGrid('getcell', i, 'languageddl');
and then, whit some magic, get the dropdowncontrol from the cell to disable the item. This is where i’m stuck..
Any hints or is this not possible?
Thanks in advance
I became an answer on the jqwidget forums, here the solution:
editor.bind('open', function (event) {
var rows = $('#jqxgridpop').jqxGrid('getboundrows');
for (var i = 0; i < rows.length; i++) {
var value = $('#jqxgridpop').jqxGrid('getcellvalue', i, "languageCode");
var item = editor.jqxDropDownList('getItemByValue', value);
editor.jqxDropDownList('disableItem', item);
};
});
Related
I have a table with cells that contain numbers styled with fonts of different colors. I would like to sum all cell values of a certain color and output that sum into a separate cell. How can I do that?
Try (B1 contains a checkbox)
=sumColor(A:A,B1)
put the formula in a range with the same color as the data to be added
add a check box to allow you updating the value when colors will be changed
the formula can be located in another sheet
with this custom function
function sumColor(range) {
var r = SpreadsheetApp.getActiveRange();
var color = r.getFontColors();
var total = 0;
var addresses = r.getFormula().match(/(?<=\().*(?=\))/g)[0].split(/[;|,]/)
for (var i = 0; i < addresses.length - 1 ; i++) {
try {
var sh = SpreadsheetApp.getSheetByName(addresses[i].split('!')[0].replace("'", ""));
var address = addresses[i].split('!')[1].trim();
}
catch (e) {
var sh = SpreadsheetApp.getActiveSheet();
var address = addresses[i].trim()
}
var colors = sh.getRange(address).getFontColors();
var values = sh.getRange(address).getValues();
for (var j = 0; j < colors.length; j++)
for (var k = 0; k < colors[i].length; k++)
if (colors[j][k] == color)
if ((typeof values[j][k]) == 'number')
total += values[j][k];
}
return total;
};
I have constructed a Grid in Vaadin 14 using a parser to extract from files as shown below:
Grid<String[]> grid = new Grid<>();
try {
List<String[]> entries = reader.readAll();
// Assume the first row contains headers
String[] headers = entries.get(0);
for (int i = 0; i < headers.length-1; i++) {
final int columnIndex = i;
String header = headers[i];
String humanReadableHeader = SharedUtil.camelCaseToHumanFriendly(header);
grid.addColumn(str -> str[columnIndex]).setHeader(humanReadableHeader).setSortable(true).setWidth("100px");
}
grid.setItems(entries.subList(1, entries.size()));
What I want to do next is add a CheckBox to every row that would return a visualization of the data in the corresponding row. So my question is two-fold:
Is there a function that already exists to emulate this behavior via clicking anywhere on a row?
If not, what would be the best way to initialize a Grid to accommodate this?
Simply add a component column:
Grid<String[]> grid = new Grid<>();
try {
List<String[]> entries = reader.readAll();
// Assume the first row contains headers
String[] headers = entries.get(0);
for (int i = 0; i < headers.length-1; i++) {
final int columnIndex = i;
String header = headers[i];
String humanReadableHeader = SharedUtil.camelCaseToHumanFriendly(header);
grid.addColumn(str -> str[columnIndex]).setHeader(humanReadableHeader).setSortable(true).setWidth("100px");
}
// Here goes your checkbox column
grid.addComponentColumn(item -> {
// Create the checkbox
}).setHeader("<the header>");
grid.setItems(entries.subList(1, entries.size()));
Ideally, I want to be able to search through an entire sheet (or range of cells) and remove any values that have been repeated in that sheet (for example, if "2" appears in A3, B8, and D4, then I want to keep it in A3 and delete it in B8 and D4).
I normally see this problem addressed by looking at one column or row for duplicates (using the UNIQUE function) but not for an entire sheet.
How can I do this?
Here's some code that will do that for an entire sheet.
Please note it will work on text and numbers and it will overwrite any formulas.
function removeDuplicates() {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
var range = sheet.getDataRange();
var values = range.getValues();
var traversedValues = [];
var rowCount = values.length;
var colCount = values[0].length;
for (var row = 0; row < rowCount; ++row) {
for (var col = 0; col < colCount; ++col) {
var value = values[row][col];
if (traversedValues.indexOf(value) > -1) {
values[row][col] = null;
} else {
traversedValues.push(value);
}
}
}
range.setValues(values);
}
References for you
Beginner's guide to coding with Google Apps Script
For loops
if...else statements
Arrays
I am trying to create a program that will invite email addresses from a column of cells. However, I only want the cells that have content in them to be used in the program and the empty cells to be ignored. Since the cells are linked to a form, as soon as the program finds a single empty cell as it searches down the column, it should stop looking for more empty cells. This is what I have so far:
function addEditor() {
var sheet = SpreadsheetApp.getActive().getSheetByName('GuestList');
var Blank = sheet.getRange('a51').getValue().isBlank;
for (var i = 2; Blank = true; i++){
var Blank = sheet.getRange(2, 1, i, 1).isBlank;
if (Blank === true){ break;
}
}
var Editors = sheet.getRange(2, 1, i, 1);
sheet.protect().addEditors([Editors]);
}
Try something like this:
function sendEmails() {
var glist=SpreadsheetApp.getActive().getSheetByName('GuestList');
var gdata=glist.getDataRange().getValues();
for (var i=1;i<gdata.length;i++){
if(gdata[i][0]){
//sendEmail
}else{
break;
}
}
}
screenshot
Hi all, i need help and i am not a coder. I am trying to achieve the same thing on sheet number 2.
My datas are imported through "=Submission!$b2" from sheet 1
i need help removing rows automatically when a specific cell on column H does not contain the value "Bekreft", i tried both codes shown here with no success.
This is what i added for script:
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName('DATA - Do Not Touch!!!'); // change to your own
var values = s.getDataRange().getValues();
for(var i=values.length;i>0;i-=1){
var lcVal=values[i-1][0].toLowerCase() //Change to all lower case
var index = lcVal.indexOf("vent"); //now you only have to check for contains "vent"
if (lcVal.indexOf("vent") > -1){
s.deleteRow(i)};
}}
Seeing as you state you are "not a coder", and the code you pasted will not help you if you are referencing data from another page, I would suggest using a filter function to achieve your goal. You would add the following formula to your second page:
=FILTER(Submission!B:B,ISNUMBER(SEARCH("Bekreft", Submission!H:H)))
If you are looking to have a script go through your static list and delete out values that do not contain "Bekreft" then you can use the following script.
function onEdit() {
var sheet = SpreadsheetApp.openById("Add Sheet ID").getSheetByName('Sheet1');
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
var values = rows.getValues();
var rowsDeleted = 0;
for (var i = 0; i <= numRows - 1; i++) {
var row = values[i];
//row for condition
if (row[7].indexOf("Bekreft")) {
sheet.deleteRow((parseInt(i)+1) - rowsDeleted);
rowsDeleted++;
}
}
};