How to get selected row data from nested row in Jqwidgets - javascript

I am using JqWidgets to generate nested grid. In my grid I am having context menu.
Here is my Nested grid details:
To show team, associated users information.
Now my target is to get id column value when user will click any option from context menu.
I tried no of approach to get it. But each time it is returning undefined.
Can you please help me to find it ?
Below is my attempts
Approach-1
jQuery("#teamMenu").on('itemclick', function (event) {
var args = event.args;
var rowindex = jQuery("#teamGrid").jqxGrid('getselectedrowindex');
if (jQuery.trim(jQuery(args).text().trim()) == "View Details") {
editrow = rowindex;
jQuery("#rowId").val(editrow);
var dataRecord = jQuery("#teamGrid").jqxGrid('getrowdata', editrow);
alert('teamId: ' +data.teamId); // here I am getting undefined
}
}
Approach-2
jQuery("#teamMenu").on('itemclick', function (event) {
var args = event.args;
var rowindex = jQuery("#teamGrid").jqxGrid('getselectedrowindex');
if (jQuery.trim(jQuery(args).text().trim()) == "View Details") {
editrow = rowindex;
jQuery("#rowId").val(editrow);
var selectedRowData = jQuery('#teamGrid').jqxGrid('getrowdata', getselectedrowindexes[0]);
alert('teamId: ' + selectedRowData.teamId); // here I am getting undefined
}
}
Approach-3
jQuery("#teamMenu").on('itemclick', function (event) {
var args = event.args;
var rowindex = jQuery("#teamGrid").jqxGrid('getselectedrowindex');
if (jQuery.trim(jQuery(args).text().trim()) == "View Details") {
editrow = rowindex;
jQuery("#rowId").val(editrow);
var selectedRowData = jQuery('#teamGrid').jqxGrid('getrowdata', event.args.rowindex);
alert('teamId: ' + selectedRowData.teamId); // each time I am getting 1st reord ID value
}
}

I had same issue in program
when use try to get selectedrowindex jQuery("#teamGrid").jqxGrid('getselectedrowindex') it's always return -1.
in my case I have set selectionmode: 'multiplecellsadvanced'
after remove this it's start working and jQuery("#teamGrid").jqxGrid('getselectedrowindex') returning select row index

Related

Method search on google sheet data from one column using google script?

I had tried to search data like below flow picture and script to search data from google sheet using google app script but the script using is not working properly but can someone tell me how to setup search function to find data like flow on image? thanx
[Flow searching data][1]
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [ {name: "Search", functionName: "searchRecord"} ];
ss.addMenu("Commands", menuEntries);
}
function searchRecord()
{
var ss = SpreadsheetApp.getActiveSpreadsheet()
var wsSearchingData = ss.getSheetByName("Searching Data")
var wsDatabase = ss.getSheetByName("Database")
var searchString = wsSearchingData.getRange("E4").getValue();
var column =1; //column Index
var columnValues = wsDatabase.getRange(2, column, wsDatabase.getLastRow()).getValues(); //1st is header row
var searchResult = columnValues.findIndex(searchString); //Row Index - 2
var searchValue = wsDatabase.getRange("B2:B2041").getValues()
var matchingDatabase = searchValue.map(searchColumn => {
var matchColumn = columnValues.find(r => r[0] == searchColumn[0])
return matchColumn = matchColumn ? [matchColumn[2]] : null
})
console.log(matchingDatabase)
if(searchResult != -1)
{
//searchResult + 2 is row index.
SpreadsheetApp.getActiveSpreadsheet().setActiveRange(sheet.getRange(searchResult + 1, 1))
}
Array.prototype.findIndex = function(search){
if(search == "") return false;
for (var i=0; i<this.length; i++)
if (this[i] == search) return i;
wsSearchingData.getRange("B11").setValue(search[0]);
wsSearchingData.getRange("C11").setValue(search[1]);
wsSearchingData.getRange("D11").setValue(search[2]);
wsSearchingData.getRange("E11").setValue(search[3]);
wsSearchingData.getRange("F11").setValue(search[4]);
return;
}
}
[1]: https://i.stack.imgur.com/HF9K8.png
var searchResult = columnValues.findIndex(searchString); //Row Index - 2
replace the above code with:
var searchResult = columnValues.filter(r=>r[1]==searchString)
You can then put searchResult directly as output in the sheet. Make sure that [1] in the above contains the column index of Name in the columnValues Array.

w2ui version 2, how can I get sellected cell name onContextMenuClick

I'm using w2ui version 2 and I have
let row = '';
let cell = '';
let grid = new w2grid({
name: 'grid'
...
...
,onClick: function (event) {
event.onComplete = function () {
row = event.detail.recid;
cell = event.detail.column;
console.log("onClick cell : " + cell );
}
}
...
...
}
in my code and it is working fine, but the code below is not working.
,onContextMenuClick: function (event) {
event.onComplete = function () {
row = event.detail.recid;
cell = event.detail.column;
console.log("onClick onContextMenuClick : " + cell);
}
}
boot is the part of same grid code.
How can I get selected cell onContextMenuClick. So I can add some specific Context Menu events to my w2ui grid.
I did try looping all sub objects of event
const keys = Object.keys(event);
for (let i = 0; i < keys.length; i++) {
console.log("onContextMenuClick event : " + keys[i] + ': ' + event[keys[i]]);
}
so I can find is there any data about cell, no luck.
var sel = grid.getSelection()[0];
only returns recid not any thing about cell.
thanks

how to read the selected option in the multiple dropdown list in the table?

On the click of submit button, I want to send all the data by ajax call to the server. I'm trying to get the selected Text of dropdown list, it gives the text of first dropdown list for each iteration.
JSFiddle https://jsfiddle.net/L7xy2kjz/10/.
This is the result of what I tried :
ScoreCard={"Heading":"pawar","parameters":[{"Name":"nikita ","Raiting":"ME","Score":"0"},{"Name":"mayuri","Raiting":"ME","Score":"0"}]},{"Heading":" schoool","parameters":[{"Name":"sss","Raiting":"ME","Score":"0"}]}
In the above code even after selecting the different options from the dropdown ie. "Raiting":"ME" . but the output displays the Text of first dropdown.
function GetObservationReview() {
var parameters = {}, status;
var ObservationArray = [];
$('#ObservationEntry, .tblObservation').each(function () {
var item = $(this).closest("tr").find('td'); //get each row
var hasclassparam = $(this).closest("tr").attr('name') === 'ObsevHeading';
if (status == 'Parameters' && $(this).attr('name') === 'ObsevHeading') { //if next tr is heading then push whole object in array till first heading
metrics = {
'Heading': Heading1,
'parameters': paramarray // paramNewArray
//work in process
}
var stringyfydata = JSON.stringify(metrics);
ObservationArray.push(stringyfydata);
metrics = {};
paramarray = [];
}
if ($(this).attr('name') === 'ObsevHeading') { //if the current row having name as heading
status == 'heading';
$.each(item, function (key, value) {
if (key == 0) {
Heading1 = ($(value).text());
}
//else if (key == 1) {
// TotalWeightage = ($(value).text());
//}
});
}
if ($(this).attr('name') === 'ObsvParameters') { //read parameters
status = 'Parameters';
var e = document.getElementById("dropDownLevelChangetrue");
var strUser = e.options[e.selectedIndex].text;
var islastchild = $(this).closest("tr").is(":last-child"); //last child
MyLevels = {}; i = 1;
$.each(item, function (key, value) {
if (key == 0) {
parametername = ($(value).text());
}
if (key == 1) {
param_Raiting = (strUser);
}
if (key == 2) {
para_Score =($(value).text());
}
});
parameters = {
"Name": parametername,
"Raiting": param_Raiting,
"Score": para_Score
}
paramarray.push(parameters);
if (islastchild === true) { // if row is last row add whole object in data
metrics = {
'Heading': Heading1,
'parameters': paramarray //parameter array that stores Paameter name and its weightage
}
var stringyfydata = JSON.stringify(metrics);
ObservationArray.push(stringyfydata); //pushing whole object in data1 array
paramarray = [];
metrics = {};
}
}
});
alert("ScoreCard=" + ObservationArray);
return ObservationArray;
}
The expected result :
ScoreCard={"Heading":"pawar","parameters":[{"Name":"nikita ","Raiting":"EE","Score":"0"},{"Name":"mayuri","Raiting":"ME","Score":"0"}]},{"Heading":" schoool","parameters":[{"Name":"sss","Raiting":"NI","Score":"0"}]}
I think you are always taking value from the same element in these lines
var e = document.getElementById("dropDownLevelChangetrue");
var strUser = e.options[e.selectedIndex].text;
Try to get them by name or something. getById always gets the first one in DOM node and ends

How to get textfiled value selected in Ext JS 3.4 grid

How do I get Ext JS 3.4 grid's textfield value selected on beforeedit listener function?
'beforeedit' : function(object) {
var rec = gridTilit.store.getAt(object.row);
var colIndex = object.column;
var rowIndex = object.row;
var cm = Ext.getCmp('grid-tilit').getColumnModel();
var valCol = cm.getColumnAt(colIndex);
var count = gridTilit.getStore().getTotalCount();
var cellXtype = valCol.getEditor().getXType();
colname = object.field;
if (cellXtype=="textfield") {
//function to select signle textfield
// cell value to selected must be executed here
} else {
rec.set(colname, "");
}
},
Adding this to function helps:
$("input[type=text]").focus(function() { $(this).select(); });

how to change value of a cell in kendoGrid from a child window?

I want to change value of a cell in kendoGrid from a child window this is my parent window code (consider that I have kendoGrid in it):
function onDataBound(e) {
var grid = $("#Grid").data("kendoGrid");
$("#d_roz").on("keypress", function (e) {
if (e.keyCode == 13) {
{
grid.addRow();
}
}
});
$(grid.tbody).on("keydown", "td", function (ev) {
if (ev.keyCode == 13) {
var row = $(this).closest("tr");
var rowIdx = $("tr", grid.tbody).index(row);
var colIdx = $("td", row).index(this);
//var data = grid.dataItem(grid.tbody.find('tr:eq(' + colIdx + ')'));
// console.log(data.cod1);
var cod1 = e.sender._data[rowIdx].cod1;
var sh_cod1 = e.sender._data[rowIdx].sh_cod1;
if (colIdx == 0 && is_open_find == false) {
cellSender = e.sender._data[rowIdx]; //this is a global variable I use
childWindow = window.open(testu, "_blank", null, false);
}});});
and in my child window I have following code :
id = ui.item.id; //this is the value I wanted from child window
window.opener.isPosted = true;
window.opener.cellSender.cod1 = id; // and I will change the value of cell here
self.close();
The problem is cell value will changed but kendo doesn't show the change until I re-focus on the grid which I don't want to do that.
What Should I do for that?
You will need to get the selected dataItem of the Grid and then update the value in that dataItem object rather than cell.

Categories