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();
Related
I have pieced together the following code using examples on Mapbox... https://codepen.io/charlie-enright/pen/ZExKOGB?editors=0010
What I want to do now is add another raster layer but have its visibility controlled by one of the existing buttons (the "geophys")button rather than to have to add an extra button.
Is it possible to have two separate raster layers controlled by the same toggle button with the script I have used? If so how will I go about doing this?
The code for the additional raster layer I want to add to be controlled by the geophys button is:
map.addSource('rudbaxton', {
'type': 'raster',
'url': 'mapbox://charlie-enright.chlrzasw'
});
map.addLayer({
'id': 'geophys1',
'source': 'rudbaxton',
'type': 'raster'
});
On top of this I would like the opacity control to adjust the opacity for the two raster layers controlled by the "geophys" button. is this possible to do as well?
Thanks,
The way the example you used is set up, the text in the button must exactly match the name of the layer you want to toggle.
This line gets the text from the button that was clicked:
const clickedLayer = this.textContent;
This line gets the current visibility of the layer with the same name const visibility = map.getLayoutProperty(clickedLayer, "visibility");`
To control two layers with one button click, you just need to add some logic to check for which button was clicked, and respond accordingly:
link.onclick = function (e) {
const clickedButtonText = this.textContent;
e.preventDefault();
e.stopPropagation();
if (clickedButtonText === "geophys") {
// assuming your two layers should always be on or off together, only check the current visibility of one of them
const visibility = map.getLayoutProperty("some-first-layer", "visibility");
// Toggle layer visibility by changing the layout object's visibility property.
if (visibility === "visible") {
map.setLayoutProperty("some-first-layer", "visibility", "none");
map.setLayoutProperty("some-second-layer", "visibility", "none");
this.className = "";
} else {
this.className = "active";
map.setLayoutProperty("some-first-layer", "visibility", "visible");
map.setLayoutProperty("some-second-layer", "visibility", "visible");
}
}
// repeat the above if statement for the other button(s)
};
As a bonus, this means you can use any text you want in the buttons, which might be a little more human-friendly than using the layer names!
I am trying to have my ag-grid start editing as soon as a new item is added. It works when grid has data already but if it's the first item in the grid it does not work.
var a = $scope.gridOptions.api.updateRowData({add: [newItem]});
$scope.gridOptions.api.refreshCells({force:true}); // does not help
$scope.gridOptions.api.startEditingCell({
rowIndex: a.add[0].rowIndex,
colKey: 'Note'
});
using ag-grid version 12.0.2. Console shows nothing.
It seems like updateRowData does not automatically start a $digest loop. Adding $scope.$apply or $timeout or anything similar alleviates the problem.
The question showed AngularJS code.
Here's an example what you'd need to do, using regular Angular.
getContextMenuItems(params) {
var result = [
{
name: 'Add new row',
action: function() {
// Add a new row at the start of our agGrid's data array
params.context.rowData.unshift({});
params.api.setRowData(params.context.rowData);
params.api.refreshCells();
// Get the name of the first column in our grid
let columnField = params.column.userProvidedColDef.field;
// Highlight the left-hand cell in our new row, and start editing it
params.api.setFocusedCell(0, columnField, null);
params.api.startEditingCell({
rowIndex: 0,
colKey: columnField,
rowPinned: null
});
},
icon: '<img src="../../assets/images/icnAdd.png" width="14"/>'
}
];
return result;
}
Hope this helps.
hey guys not sure if this is a bug or theres something I'm doing wrong, or the CSS style sheets im using are making this error, but im racking my brain on how to fix this.
I have the following code bellow in a loop, ever since I put it in a loop it no longer works as setting the selected button I had a search and some one said try set selected key, I also tried this and no luck. Now I have put them both in and it sets the selected value to neither button. I'll show you screenshots of what I mean. Any ideas on fixing it would be great.
for(var i = 0; i < results.length; i++) {
//Create buttons dynamically
var segmentItemYes = new sap.m.SegmentedButtonItem({text :"Yes", press: [this.onSEYesPress, this]});
var segmentItemNo = new sap.m.SegmentedButtonItem({text :"No", press: [this.onSENoPress, this]});
var segmentedButton = new sap.m.SegmentedButton({items : [segmentItemYes, segmentItemNo]});
//TODO:Doesn't work currently - How do we set default state?
segmentedButton.setSelectedButton(segmentItemNo);
segmentedButton.setSelectedKey(segmentItemNo);
Below is the Image the top part is what I'm getting (I clicked on no to show you what exactly happens. The bottom one is with the setSelectedKey removed but still set to no. any ideas? This is in a JS controller and it gets placed in to an xml fragment if this makes a difference or not.
I got it to work as follows, by binding the selected key to a model:
var segmentItemYes = new sap.m.SegmentedButtonItem( {
text: "Yes",
key: "foo"
});
var segmentItemNo = new sap.m.SegmentedButtonItem( {
text: "No",
key: "bar"
});
var segmentedButton = new sap.m.SegmentedButton( {
items: [segmentItemYes, segmentItemNo],
selectedKey: {
path: "test>/key"
}
});
var model = new sap.ui.model.json.JSONModel({
key: "bar"
});
sap.ui.getCore().setModel(model, "test");
I'm building an application using ag-grid enterprise 4.0.7, which uses row groups and has editable fields, keyboard navigation between editable cells is essential.
Built-in tab navigation works well, but only within a row group. Once the last editable cell in a group is reached, pressing tab does NOT jump to the next editable cell in the next group but rather to some unrelated element on the page.
Here's an example based on an ag-grid documentation sample, the athletes' names are editable, tab navigates to the next athlete, but only within one country: https://jsfiddle.net/pfhkf3bm/
field: "athlete",
editable: true
Is this the intended behavior? What's the cleanest way to extend the tab navigation to jump to the next editable item in another group?
Thanks!
This method has worked for me:
myTabToNextCell(params) {
const previousCell = params.previousCellDef;
const lastRowIndex = previousCell.rowIndex;
let nextRowIndex = lastRowIndex + 1;
// TODO renderedRowCount must contain the row count.
const renderedRowCount = this.state.rowCount;
// if (nextRowIndex >= renderedRowCount) { nextRowIndex = 0; }
if (nextRowIndex < renderedRowCount) { nextRowIndex = lastRowIndex + 1; } else {
nextRowIndex = 0;
}
const result = {
rowIndex: nextRowIndex,
column: previousCell.column,
floating: previousCell.floating
};
return result;
}
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();
}
}