Category Archives: Javascript

MongoDB map/reduce

Map/reduce in MongoDB is quite difficult the get familiar with. In this post I’ll try to explain the basics with a real-life example.

Map/reduce can be used by calling this function with the following arguments

db.collection.mapReduce(
     mapFunction,
     reduceFunction,
     {
        out: collection,
        query: document,
        finalize: function
     }
)
  • mapFunction, javascript function that will be explained below
  • reduceFunction, javascript function that will be explained below
  • out: name of the collection where the reduced data should be written to
  • query: query of the data where to apply the map/reduce on
  • finalize: function that is applied only once on the reduced data

Continue reading MongoDB map/reduce

What’s new in ExtJS 4

Some cool new features I really like in ExtJS 4 I want to share with some examples. For all the new features and to download ExtJS look at http://www.sencha.com/products/extjs/whats-new-in-ext-js-4/

Autoloading

ExtJS now supports autoloading. So you don’t have to include every file in your HTML file. For autoloading to work you should not use the new keyword anymore but instead use the Ext.create which does the same but also supports autoloading.

// Use in ExtJS 4
var about = Ext.create('Ext.window.Window', {});

// Don't use in ExtJS 4 but it will still work
var about = new Ext.window.Window({});

For autoloading to work optimal you should include the Ext.require statement to indicate that you are going to use a class. Autoloading is then done one time.

Ext.require('Ext.window.Window');
var about = Ext.create('Ext.window.Window', {});

Continue reading What’s new in ExtJS 4

ExtJS: CheckboxSelectionmodel

An ExtJS gridpanel can be extended with checkboxes so it is visual which rows are selected.

Therefor the default selectionmodel of the GridPanel should be replaced with the Ext.grid.CheckboxSelectionModel.

var checkboxselection = new Ext.grid.CheckboxSelectionModel({
    singleSelect: true,
});

Then this object is add on two different place to the GridPanel. Don’t forget the one in the column configuration, this will be the place where the actual checkboxes are coming.

var grid = new Ext.grid.GridPanel({
    store: store,
    loadMask: true,
    selModel: checkboxselection,
    columns: [
       checkboxselection,
       {header: 'Id', sortable: true, renderer: 'string', dataIndex: 'id' },
       {header: 'Name', sortable: true, renderer: 'string', dataIndex: 'name'}
    ]
});

Continue reading ExtJS: CheckboxSelectionmodel