Close

Entries with tag javascript .

JavaScript datagrid comparison

Data grids are some of the most commonly used components in business apps. But at the same time they are some of the most complex components to implement well. There are many aspects that the component needs to get right – customizability, performance, usability, accessibility, and cross-platform support.

 

After recently releasing Vaadin Grid 2, we wanted to see how it stacks up against other JavaScript grids out there. We selected four grids that are all framework agnostic – that is, they can be used together with any framework. The grids we selected for comparison are Vaadin Grid, bwt-datatable, ag-Grid, and the classic jQuery DataTables.

  Testing JavaScript grid perfomance with Chrome DevTools

So whether you're looking for a grid for your upcoming Polymer project, or are looking for the best alternative to jQuery DataTables, head on over to the comparison and see how they compare.

  Read the data grid comparison

Learn ES6 Today with Vaadin Elements - Part 3: Arrow Functions

In this short segment of our guide to ES6, you’ll learn how to use the Arrow function syntax to create cleaner code.

We will be referencing the example we wrote in the previous guides. You can read the first and second parts of this blog series here:

  1. Part 1: Promises
  2. Part 2: The Fetch API

Arrow functions

Our ES6 guide is all about making code simpler and more readable, so let’s talk about ES6’s new Arrow function syntax. Arrow functions let you write functions with straightforward syntax. Arrow functions look like parameters => expression. The result of expression is then returned. This skips writing both function and return. That may not seem like much, but it makes writing functions and callbacks so much clearer.

Let’s take a look at a few quick examples.

// ES5 way
var doubleES5 = function(x) {
  return x * 2;
}

var addES5 = function(a, b) {
  return a + b;
}

// ES6 way
var doubleES6 = x => x * 2;

var addES6 = (a, b) => a + b;

As you can see, writing arrow functions is a breeze. If you need to do more work in a function, then you can enclose the right side in curly braces to make a regular block expression. In this case, the return is no longer implicit and does need to be called.

var doWork = (x, y, z) => {
  // ... do stuff ...
  return someResult;
}

Caveat

One thing to note is that arrow functions do not create their own context, so this inside of an arrow function is the same as the enclosing scope. While on the whole, this makes function code more clear, this can lead to trouble if you’re not expecting it.

var scope = this;

var container = {
    classicSyntax: function() {
        console.log(this === scope); // False!
    },

    arrowSyntax: () => {
        console.log(this === scope); // True!
    }
}

container.classicSyntax();
container.arrowSyntax();

You can learn more about arrow functions at this great article on Mozilla Hacks.

Cleaning up our code

Now we’ll finish tidying up our code with the new arrow function syntax. Follow along at jsbin here.

Arrow functions are particularly useful for cleaning up Promises and then blocks, so we can shorten getJSONPromise even more.

function getJSONPromise(url) {
  return fetch(url).then(response => response.json());
}

I’ve similarly updated the rest of the code to use arrow functions, which you can see in the finished code.

Browser support

Arrow functions are available in all modern browsers, with the exception of Internet Explorer and Opera Mini.

Conclusion

Arrow functions is just another way the evolving web platform is making coding simpler. When the constructs you use are streamlined, then your code itself will be clearer and understandable.

In the next episode of our series on ES6 we’ll cover a few more advanced features of the platform.

Learn more about <vaadin-grid> and Vaadin Elements

Vaadin and AngularJS - happy together

You certainly read and hear a lot about JS frameworks, foremost AngularJS, and as a Vaadin developer you might just wonder what to make of it: ignore it? (Would be a shame, there is great stuff out there.) Jump ship altogether? (Would be a shame, too - you’d loose Vaadin.) But fortunately, it’s not really Vaadin or AngularJS - it’s rather Vaadin AND AngularJS.

There is an add-on available that lets you combine the best of Vaadin and AngularJS: Vaangular

Some reasons why you might want to do that:

  • mix and match skill within your team
  • increase responsiveness with bad network connection (by doing client-side logic)
  • reuse existing AngularJS-based assets
  • have an alternative to custom GWT development

And: you don’t have to do any GWT development (and no REST-backend-HTTP-calls either - because you have Vaadin for that, haven’t you?).

Here’s an example that uses Vaangular to increase responsiveness. Imagine you want to provide a weather forecast with a slider to select the time and get some more details: 

Slider with clock times and temperature for each time - i.e. a weather forecast

For a maximal user experience, even for users with slow network connection, you'll want to minize the server roundtrips. This would be a perfect task for your client side developer, but he/she is probably more keen to use AngularJS than GWT.

To include an AngularJS-based slider view into a Vaadin UI, you have to include the Vaangular add-on and follow these steps (we have the full code available on Github)

First: create an HTML fragment with AngularJS bindings:

<div ng-controller="WeatherController">
    <div ng-bind-html="content()"></div>
    <input type="range" min="0" max="{{userState.times.length-1}}" 
            step="1" ng-model="sliderPos" />
    <div>
        <div ng-repeat="t in userState.times" 
                ng-click="moveSlider($index)">
            <div>{{t}}</div>:00
        </div>
    </div>
</div>

Second: create a matching AngularJS controller (and a unit test, please! – you can download ours) 

angular.module('weatherModule', ['ngSanitize'])
.controller('WeatherController', function($scope, $connector, $sce) {
    $scope.sliderPos = 0;
    $scope.content = function() {
        var res = $scope.userState.entries[$scope.sliderPos];
        return $sce.trustAsHtml(res);
    };
    $scope.moveSlider = function(val) {
        $scope.sliderPos = val;
    };
});

You’re almost there. All what’s left is to write a Vaadin component that’s derived from de.akquinet.engineering.vaadin.vaangular.angular.NgTemplate or de.akquinet.engineering.vaadin.vaangular.angular.NgTemplatePlus. You can set weather data like this: 

public void setData(int[] times, String[] entries) {
    validateParameters(times, entries);
    this.times = times;
    this.entries = entries;
    setUserState("times", times);
    setUserState("entries", entries);
    markAsDirty();
}

Everything put in via setUserState is forwarded to AngularJS. 

Add your component to the UI, fire off the server – and enjoy.

Of course, you can also submit data from the client to the server (both immediate and deferred) and call methods on the server. You can also apply Vaadin style classes to HTML generated by AngularJS – it’s all up to you

See more detailed instructions and more extensive examples

(also available in German)

Oliver Damm, Axel Meier, Sebastian Rothbucher
Oliver Damm, Axel Meier and Sebastian Rothbucher are Vaadin & Web developers and trainers working for akquinet AG in Hamburg, Germany. When not watching FC St. Pauli play or chilling at Lake Alster they craft business web applications – with Vaadin, of course.

— 3 Items per Page
Showing 1 - 3 of 4 results.