How to make KendoUI grid.setOptions working with MVVM? - mvvm

In latest release kendo introduced ability for saving grid state and layout which I can't make working with the javascript MVVM declared grid.
My problem can be reproduced by performing few simple steps with bellow given jsfiddle code
Resize columns
Save the state
Move the columns to some other width
Load the state
What I would expect to be the outcome is that after step #4, column width will be reset to saved state.
What I see in my repro is that grid.setOptions just reset the grid to initial unmodified state.
Here's the jsfiddle repro link also given as inline code snippet here...
$(document).ready(function () {
var dataSource = new kendo.data.DataSource({
data: [
{name: 'John', surname: 'Smith'},
{name: 'John', surname: 'Doe'}
]
});
var dataContext = new kendo.data.ObservableObject({
dataSource: self.remoteDataSource
});
var viewTemplate =
"<div id='grid' data-role='grid' data-sortable='true' data-editable='true' " +
"data-resizable='true' data-reorderable='true' data-navigatable='true' " +
"data-columns=\"[{'field':'name', 'title':'Name'}, {'field': 'surname', 'title': 'Surname'}]\"" +
" data-bind='source: dataSource' />";
// now get the main view
var kendoView = new kendo.View(viewTemplate, {
wrap: false,
model: dataContext
});
kendoView.render($("body"));
var grid = $("#grid").data("kendoGrid");
$("#save").click(function (e) {
e.preventDefault();
var options = grid.getOptions();
console.log(options);
localStorage["kendo-grid-options"] = kendo.stringify(options);
});
$("#load").click(function (e) {
e.preventDefault();
var optionsString = localStorage["kendo-grid-options"];
if (optionsString) {
var options= JSON.parse(optionsString);
console.log(options);
grid.setOptions(options);
}
});
});
<link href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.metro.min.css" rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script>
<body>
<div class="box">
Save State
Load State
</div>
</body>

I have just received the answer from Telerik customer support with a working resolution tip
This weird behavior is coming from the fact that the options are first provided through data-attributes and then the setOptions method of the Grid new options are passed through JavaScript, however the data-attribute options are still on the element and they are still considered options higher priority at this point.
As a temporary work-around you can remove the data-attribute that gives the column options and then the new options should be applied.

Related

ArcGIS JavaScript API Popup Not Referencing REST Service Layer

The content in the popup created through the variable "popupCustom" is displaying string instead of referencing the specified field {IN_COUNTRY}. I followed the ArcGIS JS API Popup Tutorials, & can't see what my error is in failing to grab the attributes associated with that field. Here's the code -- any help is greatly appreciated!
*note: feature layer url within "Cyber_Areas" variable points to REST URL for referenced Feature Class.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Search widget with multiple sources - 4.6</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.6/esri/css/main.css">
<script src="https://js.arcgis.com/4.6/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/BasemapToggle",
"esri/widgets/Legend",
"esri/layers/TileLayer",
"esri/layers/FeatureLayer",
"esri/widgets/Search",
"esri/widgets/LayerList",
"esri/PopupTemplate",
"dojo/on",
"dojo/domReady!"
], function(
Map,
MapView,
BasemapToggle,
Legend,
TileLayer,
FeatureLayer,
Search,
LayerList,
PopupTemplate,
on
) {
var Cyber_Areas = new FeatureLayer({
url: "*inserturl*",
outFields: ["IN_COUNTRY"],
popupTemplate: popupCustom
});
var map = new Map({
basemap: "osm"
});
map.add(Cyber_Areas);
var view = new MapView({
container: "viewDiv",
map: map,
center: [-87.172865, 34.077613], // lon, lat
zoom: 16
});
var searchWidget = new Search({
view: view,
popupOpenOnSelect: false
});
view.ui.add(searchWidget, {
position: "top-left",
index: 0
});
var popupCustom = searchWidget.on('select-result', function(evt){
//console.info(evt);
view.popup.open({
location: evt.result.feature.geometry, // location of the click on the view
title: "Service Availability:", // title displayed in the popup
content: "<p><b>{IN_COUNTRY}"
});
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
From your code you are mixing the popup template value with when to display it. And those are two different things.
First, you are not setting correctly the popup template of the layer. It should be a PopupTemplate.
It seems to me that in you code the layer definition should be something like this,
var Cyber_Areas = new FeatureLayer({
url: "*inserturl*",
popupTemplate: {
outFields: ["IN_COUNTRY"],
title: "Service Availability:",
content: "<p><b>{IN_COUNTRY}</b></p>"
}
});
Now if you don't want the default behavior of the popup (left click on a feature), you cant disable it like this,
view.popup.autoOpenEnabled = false; // <- disable view popup auto open
And then you can open it wherever you want like this,
view.popup.open({ // <- open popup
location: evt.result.feature.geometry, // <- use map point of the event result
fetchFeatures: true // <- fetch the selected features (if any)
});
You have to understand that the fields you use in the content of the popup template are related to the layer. That is why i set in the popup of the view to fetch the results.

Google Chart - Using Spreadhseet Source does not resolve

Using the tutorial from google on using a spreadsheet as data for a chart I have created the following.
Tutorial
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {packages: ['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawSheetName() {
var query = new google.visualization.Query('https://docs.google.com/spreadsheets/d/15l3ZK45hv2ByOfkUiAKoKp-Z9a1u1-Q_rsLS7SqC51E/editgid=0&headers=1');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, { height: 400 });
}
}}
</script>
</head>
<body>
<!-- Identify where the chart should be drawn. -->
<div id="chart_div"/>
</body>
However no chart resolves, I have made the link public.
If I share the link it is https://docs.google.com/spreadsheets/d/15l3ZK45hv2ByOfkUiAKoKp-Z9a1u1-Q_rsLS7SqC51E/edit?usp=sharing
Following the docs and not sure where my error is.
This SO answer more about drive-sdk creates the key from a script from a new file, I don't really understand it and nuclear how you can obtain the correct URL for existing spreadsheets.
Would be great if there could be a consolidated answer obtaining correct sheets URL's.
Is this what you are trying to achieve?
If yes, you can check how it works here.
EDIT
Since I notice in the comments you want to query the spreadsheet and not use the entire spreadsheet, this is the logic to query with.
First, these are the basic components of the url to query:
var BASE_URL = "https://docs.google.com/a/google.com/spreadsheets/d/";
var SS_KEY = "stringSS_Key";
var BASE_QUERY = "/gviz/tq?tq=";
var partialUrl = BASE_URL + SS_KEY + BASE_QUERY;
Notice the BASE_QUERY variable
The first bit of the url is in the partialUrl variable.
Then, you need to use the Query Language that google provides. An example would be:
var queryToRun = 'select dept, sum(salary) group by dept';
You then need to call encodeURIComponent() on it, and add it to the partial URL. The final URL then becomes
var finalUrl = partialUrl + encodeURIComponent(queryToRun);
Only then you can run the google.visualiation.query as I suspect you intend.
var query = new google.visualization.Query(finalUrl);

Jquery-ias breaking clickable row

I am using jQuery 2.1.1, and have been using it to add 'clickable' to rows returned from a database using this:
<script type="text/javascript">
jQuery( function($) {
$('tbody tr[data-href]').addClass('clickable').click( function() {
window.location = $(this).attr('data-href');
});
});
</script>
That has been working fine. I have now added jquery-ias (2.1.2), and only the first page of returned results has clickable rows.
My jquery-ias code is as follows:
<script type="text/javascript">
$(document).ready(function() {
// Infinite Ajax Scroll configuration
jQuery.ias({
container : '.wrap', // main container where data goes to append
item: '.item', // single items
pagination: '.nav', // page navigation
next: '.nav a', // next page selector
negativeMargin: 250,
});
});
</script>
Jquery-ias is working fine, the pages are loading as needed, but the resultant rows are not clickable.
Inspecting the page in Chrome shows that the subsequently loaded rows have not had the clickable attribute added.
The relevant row in the php is this:
<tr class='resultsrow item' <?php echo "data-href='carddetail.php?setabbrv={$row['setcode']}&number={$row['number']}&id={$row[1]}'"; ?>>
All works fine if I use either, but how do I get them to play nicely together?
EDIT.....
OK, I have worked around it using the jquery-ias built-in pageChange event.
jQuery.ias().on('pageChange', function(pageNum, scrollOffset, url) {
var delay=1000;
setTimeout(function(){
jQuery( function($) {
$('tbody tr[data-href]').addClass('clickable').click( function() {
window.location = $(this).attr('data-href');
});
});
},delay);
});
This way when ias finds a page change, it waits a second for the page structure to load, and then applies the clickable class.
I can't see this working if it's waiting for images though... doesn't have to for this instance, but there's got to be a better way to do this.
Any pointers?
the better way would be to use the rendered event, for example:
jQuery.ias().on('rendered', function(item) {
var $items = jQuery(items);
$items.each(function() {
jQuery('tr[data-href]', $this).addClass('clickable').click(function() {
window.location = $(this).attr('data-href');
});
});
});

how to create dojo data onclick event for dojo dynamic tree in zend framework for programatic approach

i am new to Zend framework and dojo.i have created dynamic tree structure using dojo in zend framework but i want to make on click of each folder and element of tree structure to naigation to another form by writing a function .Pleas check my code and help me i have gone through some dojo on click event link and could not solve ..
<html>
<head>
<title> Tree Structure </title>
<link rel="stylesheet" href=/dojo/dijit/themes/ claro/claro.css" />
<script type="text/javascript" src="/ dojo/dojo/dojo.js"
djConfig="parseOnLoad:true, isDebug:true" >
</script>
<script type="text/javascript">
dojo.require("dojo.parser");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.TabContainer")
dojo.require("dijit.form.Button");
dojo.require("dojo.data.ItemFileReadStore");
dojo.require("dijit.tree.ForestStoreModel");
dojo.require("dijit.Tree");
dojo.require("dojo.parser");
function myTree( domLocation ) {
var store = new dojo.data.ItemFileReadStore({url: "http://localhost/CMTaSS_module1.0/public/dojo/cbtree/datastore/Family-1.7.json"});
var treeModel = new dijit.tree.TreeStoreModel({
store: store,
query: { name:'John'}
});
var tree = new dijit.Tree( {
model: treeModel,
id: "mytree",
openOnClick: true
});
tree.placeAt( domLocation );
}
var tree_obj = new dijit.Tree({
model: treeModel
},
"tree_obj");
dojo.connect(tree_obj, 'onClick', function(item, node, evt){
console.log("Item", item);
console.log("Node", node);
console.log("Event", evt);
//console.log('node: ' +tree_obj.getLabel(node));
//console.log('event: ' +tree_obj.getLabel(evt));
console.log('identifier: ' + tree_obj.getLabel(item))
});
</script>
</head>
<body class="claro"><br><br><br>
<div id="CheckboxTree">
<script type="text/javascript">
myTree("CheckboxTree");
</script>
</div>
</body>
</html>
Looks like your code sample is not formatted correctly as some of the logic is outside the myTree function. I used jsbeautifier.org to confirm this.
Other notes...
You should wait until dojo is ready. Either use dojo.addonload or, create a widget and reference that widget in the html portion of your code. Widgets are amazing and are what make dojo great, so getting a grasp on how they work will pay dividends.
Also note that if creating a widget programmatically (new dijit.Tree), you should call startup on it. This is not needed when creating it declaratively (inline html).
I hope this helps.

dojo:How to format the date type in grid

here is my code. as a result, it can't format any date according to the datePattern.
thank you for any help in advance
<script type="text/javascript">
var store = new dojo.data.ObjectStore({objectStore:new dojo.store.Memory({data:[{MyDate:new Date(2011,1,1)},{MyDate:new Date(2011,1,1)}]})});
dojo.addOnLoad(function()
{
var layout=
[
{field:"MyDate",datatype:"date",dataTypeArgs:{datePattern:"yyyy"}}
];
Grid = new dojox.grid.EnhancedGrid(
{
id:"Grid",
selectable:true,
store: store,
structure: layout,
});
Grid.placeAt("GridLayer");
Grid.startup();
});
</script>
<div id="GridLayer" style="width:98%;height:600px"></div>
Docs are being improved for this. Look at the current staging docs for DataGrid near the bottom where it says "See Also" the link for "Demos on how to display and edit date value in grid cells"