jqGrid change row values - jqgrid

How can I change data already present in my grid's row with different data on click of a button?
I want to update the values of selected row with new values.

The code could look like
var myGrid = $("#list");
var selRowId = myGrid.jqGrid('getGridParam','selrow');
myGrid.jqGrid('setRowData',selRowId,newData);
where the newData in the object of data that contain the new values. The structure of array is in type name:value (for example {firstName:"foo", lastName:"bar"}). You can examine the current data from the row with
var oldData = myGrid.jqGrid('getRowData',selRowId);

Related

Automatically create a new sheet with data of a row in the mastersheet

Consider I have a mastersheet with names in column A and a link in colum B, starting in row 2.
The code below, for a reason I don't understand, creates only one new sheet with the name in row 2, and sets the value of the row 3 in the newly created sheet.
I'd like that to work as followed :
create a sheet with the name in col A
set values of col A and col B in the newly created sheet
Can someone help me figure out what's going on ?
I read the documentation about loops and getRange but I can't figure it out..
Thank you very much
function createNewSheets() {
var dataSheet = SpreadsheetApp.getActiveSpreadsheet();
var values = dataSheet.getSheetByName('mastersheet').getRange('A2:B').getValues();
// Get sheet with current swimmer name:
var sheet = dataSheet.getSheetByName(swimmerName);
var col = values[i]; // Current row
var swimmerName = col[0]; // swimmer name
// Iterate through all rows of data from "mastersheet":
for (var i = 1; i < values.length; i++) {
// Check if sheet with current swimmer name exists. If it doesn't it creates it:
if (!sheet) {
sheet = dataSheet.insertSheet(swimmerName);
}
// Sets current row of data to the new sheet:
sheet.getRange(1, 1, col.length, col[0].length).setValues(col)
}
}
I believe your goal as follows.
You want to retrieve the values from the columns "A" and "B" from "mastersheet" sheet.
You want to use the values of column "A" retrieved from "mastersheet" sheet as the sheet names.
When the sheet of the retrieved sheet name is not existing in the active Spreadsheet, you want to insert new sheet with the sheet name.
When the new sheet is inserted, you want to copy the same row of the sheet name to the inserted sheet.
You want to achieve this using Google Apps Script.
Modification points:
In your script,
At var sheet = dataSheet.getSheetByName(swimmerName), swimmerName is not declaread.
When swimmerName is not declared elsewhere, an error occurs at this line.
At var col = values[i], i is not declared.
In the for loop,
the 1st index is 1. From getRange('A2:B'), in this case, the values are retrieved from 3rd row.
swimmerName and col are not changed.
In order to achieve your goal, I would like to propose the following flow.
Retrieve the current sheet names.
Retrieve the values from "mastersheet" sheet.
Using the retrieved sheet names and values, the new sheets are inserted and the values are put.
When above flow is reflected to a script, it becomes as follows.
Sample script:
function createNewSheets() {
// 1. Retrieve the current sheet names.
var dataSheet = SpreadsheetApp.getActiveSpreadsheet();
var sheetNames = dataSheet.getSheets().map(s => s.getSheetName());
// 2. Retrieve the values from "mastersheet" sheet.
var masterSheet = dataSheet.getSheetByName('mastersheet');
var values = masterSheet.getRange('A2:B' + masterSheet.getLastRow()).getValues();
// 3. Using the retrieved sheet names and values, the new sheets are inserted and the values are put.
values.forEach(r => {
if (!sheetNames.includes(r[0])) {
dataSheet.insertSheet(r[0]).appendRow(r);
sheetNames.push(r[0]);
}
});
}
In this sample script, sheetNames is growing in the loop and that is used for checking the duplicate sheet names.
References:
getSheets()
insertSheet(sheetName)
appendRow(rowContents)
forEach()

Oracle APEX Interactive Grid: Is there a way to get the corresponding column name, when clicking in a data cell in the Interactive Grid

I have a Dynamic Action which should get the data from the model, depending on the clicked column. Let 's say I have two columns in the interactive grid, column A and B. Depending on the column I clicked in, the DA should be executed and execute a query with the value from column A or B.
The DA is actived on doubleclick and I have the following source to get the value from the IG model.
var regionStaticId = $(this.triggeringElement).closest("div.js-apex-region").attr('id');
var grid = apex.region( regionStaticId ).widget().interactiveGrid("getViews", "grid");
var model = grid.model;
var record = grid.getSelectedRecords()[0];
var value;
// Code to find the the clicked column comes here
if (record) {
value = model.getValue(record, columnName);
}
Now, what I can do is add an extra css class to the particular cells, with the name of the source column. But that would be like hardcoding in my opinion. Like this.
if ($(this.triggeringElement).hasClass('columnA')) {
columnName = 'COLUMN_A';
}
else if ($(this.triggeringElement).hasClass('columnB')) {
columnName = 'COLUMN_B';
}
Is there a way to determine the clicked column, based on the triggering element?
Help is very much appreciated.

Iterate through jqGrid update every row for a column

I wish to iterate through jqGrid, and for a given column (ie: the second) I wish to insert a value. How do you find the first data row? The documentation warns to not use getRowData if updating row or cell data.
This is what I'm using, but it seems clumsy:
function loadCompleted() {
var $grid = jQuery("#jqGrid"), rows = $grid[0].rows;
for (var i = 1; i < rows.length; i++) {
var row = rows[i];
var id = row.cells[0].innerHTML;
$(row.cells[1]).html("<a href='#' onclick='deleteApp(" + id + "); return false;'>Delete</a>");
}
}
... this works, but it makes the assumption that the first data row is the second row in table #jqGrid. It also relies on index values for columns 1 and 2.
Is there any way to use setRowData when the documentation warns to not use getRowData when editing the row or cells?
The first row in grid is hidden and is used in the jqGrid for internal purposes.
I think that using a custom formatter will do the job.
Example of custom formatter can be found here. If you use Guriddo jqGid you may look into the docs for the parameters passed.

adding values to a row in jqgrid

I am using ajax function to call a method on server side which will return a set of values, I need to add these values to the next row of a jqgrid. How to insert values to a jqid by iterating the rownumber?
After you receive the data from the the server you can add there to the grid. For example, if your grid has colModel with column names 'invid','invdate','amount','tax','total','note'. The code which add the row could be about following
var myfirstrow = {invid:"1", invdate:"2007-10-01", note:"note",
amount:"200.00", tax:"10.00", total:"210.00"};
$("#grid_id").jqGrid("addRowData","1", myfirstrow);
where "1" is the id of the data which you want to add.
If you want to add data to a special position in the grid, for example, after the selected row you can do almost the same:
var grid = $("#grid_id");
var selRowId=grid.jqGrid('getGridParam','selrow');
var myData = {invid:"1", invdate:"2007-10-01", note:"note",
amount:"200.00", tax:"10.00", total:"210.00"};
grid.jqGrid("addRowData", "1", myData, "after", selRowId);
See Data Manipulation part of the jqGrid documentation. By the way with respect of addRowData method you can add many rows to a grid at one call. In the case the data parameter must be array of row data.

JQgrid : specific value from a selected row

how to get a value of a (hidden) column, from the selected row. that is, the cell value needs to be from the cell identied by colName, and the selected row (not using multi select). From the API i see the method getGridParam("selrow") for reading the row, may be able to combine with other methods.. but, any convenient method available? a code snippet would save lot of time... \
thanks.
You should use getCell function to read the value from the cell identified by row id. So if you need a data from the column 'MyColName' of selected row you can do this with the following code:
var grid = jQuery('#list');
var sel_id = grid.jqGrid('getGridParam', 'selrow');
var myCellData = grid.jqGrid('getCell', sel_id, 'MyColName');
If you need read full data of a row you can use getRowData instead of getCell. More about methods supported by jqGrid you can read in the documentation (see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods).

Resources