How to remove elements based on id - jointjs

I want to remove elements based on ID with double click
Tried this but it is not working:
paper.on('cell:pointerdblclick', function (cellView,cell)
{
selectedId = cellView.model.id;
selected = cellView.model;
$.each(cellsAdded, function(index, value)
{
if(selectedId !== cellsAdded[index])
{
selected.remove();
}
});
});
These are the cells in the graph:
var cellsAdded = graph.addCells([sidebar, rect, circle1, circle2, circle3, rectGroup0, diamond]);
All of the above cells have ids and I dont want to remove them, I only want to remove other elements which are not part of the above

Related

How to get row number in SlickGrid by pressing the Enter key-Solved

Seems like a simple task but I have been unsuccessful so far using Slickgrid to get the row number of the highlighted row in a grid when I press a key, specifically the Enter key. I need no data, just the row number so I can use it to reference an array element.
I have managed to do this with the mouse using the onDblClick event handler but not with the simple onKeyDown handler.
Here is the function I use to fill the grid with data which I call when specifically needed:
var grid;
function ttesting(){
var data=[];
load_text_resource(descsource);
grid = new Slick.Grid("#myGrid", data, columns, options);
grid.invalidate();
//load data from multidimensional array:
for (var i = 0; i < maxdesc-2; ++i) {
data[i] = {
aName: descarray[i][2] + " " + descarray[i][3] + descarray[i][4] + descarray[i][5] + descarray[i][6],
aTitle: descarray[i][8],
aDesc:descarray[i][9]
};
}
grid.setOptions(options);
// the following mouse handler works:
grid.onDblClick.subscribe(function(event) {
var cell = grid.getCellFromEvent(event),
row = cell.row;
alert(descarray[row][10]);
});
//This keyDown handler does not work:
grid.onKeyDown.subscribe(function(event) {
var cell = grid.getCellFromEvent(event),
row = cell.row;
if (event.keyCode == 13) {
alert(descarray[row][10]);
}
}
grid.setSelectionModel(new Slick.RowSelectionModel());
grid.render();
}
All I need to know is the row number of the highlighted row when I press the Enter key. I have also tried using instead in the above with no success:
if (event.keyCode == 13) {
selectRow = grid.getSelectedRows();
alert(selectRow);
}
Suggestions welcome.
The traditional way to do this is to create a custom formatter for the ID column, and embed the value (ie. the row id) into the button or link displayed. For example, here's an edit link that I use to open an external page:
function EditLinkFormatter(rowIndex, cell, value, columnDef, grid, dataProvider) {
if (value == null || value === "" || !columnDef.hyperlink) { return "-"; }
if (typeof value == 'string') { value = urlEncode(value); }
return 'edit';
}
This uses value, which is the value of the ID column for the row, but rowIndex is what you are after. It's there in the formatter parameters too.
Found the solution. I needed to include the args variable in the event function:
grid.onKeyDown.subscribe(function(event,args) {
if (event.keyCode == 13) {
var cell = args.cell,
row = args.row;
alert(descarray[row][10]);
}
});

How to amend Google app script to search from 2 columns instead of 1 and return entire row if both columns match?

How can I amend this app script to search from Column A and Column B?
Column A = User ID
Column B = Password
So the user must key in the User ID and Password correctly, then the matching rows will show up accordingly. If the user ID is correct, but password entered is wrong, no rows will show up.
function doGet() {
return HtmlService.createTemplateFromFile('Index')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
/* PROCESS FORM */
function processForm(formObject){
var result = "";
if(formObject.searchtext){//Execute if form passes search text
result = search(formObject.searchtext);
}
return result;
}
//SEARCH FOR MATCHED CONTENTS
function search(searchtext){
var spreadsheetIds = ['Workbook1','Workbook1'];
var dataRages = ['Sheet1!A2:K','Sheet2!A2:K'];
var ar = [];
const colIndex = 0; // Column A
spreadsheetIds.forEach((spreadsheetId, i) => {
var data = Sheets.Spreadsheets.Values.get(spreadsheetId, dataRages[i]).values;
data.forEach(function(f) {
if (f[colIndex] == searchtext) {
ar.push(f);
}
});
});
return ar;
}
Thank you!
First, this is tagged with Excel and Google app script / sheets. They are not the same.
Can you provide more information, what is in formObj.searchtext? This looks like it is taking a search term from a form, and checking if it is in Col A of either workbook. If it is in the first column, it returns the entire row.
In order for it to check two things, you need to first get both from the formObject.
In this example, going to use the keys formObj.userId and formObj.password, you will need to change the keys to match what is passed over in the formObj.
function doGet() {
return HtmlService.createTemplateFromFile('Index')
.evaluate()
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL);
}
/* PROCESS FORM */
function processForm(formObject){
var result = "";
// define the object values for ease of reading
let userID = formObject.userID;
let password = formObject.password
//check if both variables have values, if so run search and pass the two variables
if(userID && password ){
result = search(userID, password);
}
return result;
}
//SEARCH FOR MATCHED CONTENTS
function search(userID, password){
var spreadsheetIds = ['Workbook1','Workbook1'];
var dataRages = ['Sheet1!A2:K','Sheet2!A2:K'];
var ar = [];
// add the second column index for the password column
const idIndex = 0; // Column A
const passIndex = 1; // Column B
spreadsheetIds.forEach((spreadsheetId, i) => {
var data = Sheets.Spreadsheets.Values.get(spreadsheetId, dataRages[i]).values;
data.forEach(function(f) {
// for each row of data, check if the first column matches the userID
// AND the second column matches the password, if true, push that row into ar
if (f[idIndex] == userID && f[passIndex] == password) {
ar.push(f);
}
});
});
return ar;
}

Leaflet, geojson: filter out entire features/objects with a null value in them

I have a geojson file which I'm getting from this website which somehow contains corrupt data, with a coordinate value = null.
http://measuringamsterdam.nl/datalist/kijk/
And I'm using it in my code like this:
//Retrieve all data and add to map
$.each(datalistObject['idlist'], function(key, value) {
$.getJSON('http://measuringamsterdam.nl/datalist/kijk/' + value['id'], function(data) {
textbox = value['name'];
var dataid = L.geoJson([data], {
style: function (feature) {
return feature.properties && feature.properties.style;
},
onEachFeature: onEachFeature,
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: value['icon']
});
}
}).addTo(jsonGroup);
console.log(jsonGroup);
},function(xhr) { console.error(xhr); });
});
Now somehow I need to filter out the features/objects where the coordinates have a null value.
I really need to filter the data that point in my code since I need the + value['id'] part in the getJSON code.
Ane ideas?
Using the following code you will generate a new array. Which will include only the filtered data.
var newArray = data.filter(function (el) {
return el.value != 'null';
});
You can also apply multiple filters, for example:
return el.value_a != 'null' && el.value_b > 100;
Hopefully this will work!

Flot remove dataseries

This is how I remove data points upon clicking a datapoint:
item.series.data[item.dataIndex].shift()
item.series.data[item.dataIndex].shift()
Whats the code to delete the entire series that the data point belongs to?
I'm guessing you are doing this from a plotclick handler:
$("#placeholder").bind("plotclick", function (event, pos, item) {
if (item){
var someData = plot.getData(); //get the series array
someData.splice(item.seriesIndex,1); //remove the index of the one clicked
plot.setData(someData); //set the data
plot.setupGrid();
plot.draw(); //redraw
}
});
Working fiddle here.
EDITS FOR COMMENTS
Updated fiddle here which deletes from multiple graphs based on series name instead of index position.
$(".chart").bind("plotclick", function (event, pos, item) {
if (item){
var label = item.series.label;
$([plot1, plot2]).each(function(i,plotObj){
var someData = plotObj.getData();
for (var i=0; i<someData.length; i++){
if (someData[i].label == label){
someData.splice(i,1);
}
}
plotObj.setData(someData);
plotObj.setupGrid();
plotObj.draw();
});
}
});

How to Handle textbox values on sever side

I have three textboxes.In textbox1 and in textbox2 i entered a number Like ->
Textbox1-0123456789
Textbox2-0123-456-789
Textboxe3-0123-456-789
Now on server side i.e on aspx.cs page i need to check the numbers is it same or not and only one distinct number will be saved in database
//Get the values from text box and form a list
//validate against a regular expression to make them pure numeric
//now check if they are all same
List<string> lst = new List<string>()
{
"0123-456-A789",
"0123-456-A789",
"0123-456-789"
};
Regex rgx = new Regex("[^a-zA-Z0-9]");
//s1 = rgx.Replace(s1, "");
for (int i = 0; i < lst.Count; i++)
{
var value = lst[i];
value = rgx.Replace(value, "");
lst[i] = value;
}
if (lst.Any(num => num != lst[0]))
{
Console.WriteLine("All are not same");
}
else
{
Console.WriteLine("All are same");
}
//if all are same, pick an entry from the list
// if not throw error
HOPE THIS MAY GIVE U AN IDEA !!!!
If we apply replace("-","") than from every textbox it will remove dash.The number which is same like in
textbox1-0123456789
textbox2=0123-456-789
textbox3=678-908-999
than replace will remove dash from textbox3 also which we dont want.
so For this we have to apply not exists operation of linq.
List strMobileNos = new List();
Regex re = new Regex(#"\d{10}|\d{3}\s*-\s*\d{3}\s*-\s*\d{4}");
!strMobileNos.Exists(l => l.Replace("-", "") == Request.Form["txtMobNo2"].Replace("Mobile2", "").Replace("-", ""))

Resources