/grid-editor

Visual javascript editor for the bootstrap grid system, written as a jQuery plugin.

Primary LanguageJavaScriptMIT LicenseMIT

Grid Editor

Grid Editor is a visual javascript editor for the bootstrap grid system, written as a jQuery plugin.

Preview

Installation

  • Dependencies: Grid Editor depens on jQuery, jQuery UI, and Bootstap, so make sure you have included those in the page. If you want to use the tincyMCE integration, load tinyMCE en tinyMCE jQuery plugin as well.
  • Download the latest version of Grid Editor and include it in your page:
<!-- Make sure jQuery, jQuery UI, and bootstrap 3 are included. TinyMCE is optional. -->
<link rel="stylesheet" type="text/css" href="grid-editor/dist/grideditor.css" />
<script src="grid-editor/dist/jquery.grideditor.min.js"></script>

Usage

$('#myGrid').gridEditor({
    new_row_layouts: [[12], [6,6], [9,3]],
});
// Call this to get the result after the user has done some editing:
var html = $('#myGrid').gridEditor('getHtml');

Methods

getHtml: Returns the clean html.

var html = $('#myGrid').gridEditor('getHtml');

Options

new_row_layouts: Set the column layouts that appear in the "new row" buttons at the top of the editor.

$('#myGrid').gridEditor({
    new_row_layouts: [[12], [6,6], [9,3]],
});

row_classes: Set the css classes that the user can toggle on the rows, under the settings button.

$('#myGrid').gridEditor({
    row_classes: [{'Example class', cssClass: 'example-class'}],
});

col_classes: The same as row_classes, but for columns.

row_tools: Add extra tool button to the row toolbar.

$('#myGrid').gridEditor({
    row_tools: [{
        title: 'Set background image',
        iconClass: 'glyphicon-picture',
        on: { 
            click: function() {
                $(this).closest('.row').css('background-image', 'url(http://placekitten.com/g/300/300)');
            }
        }
    }]
});

col_tools: The same as row_tools, but for columns.

custom_filter: Allows the execution of a custom function before initialization and after de-initialization. Accepts a functions or a function name as string. Gives the canvas element and isInit (true/false) as parameter.

$('#myGrid').gridEditor({
    'custom_filter': 'functionname',
});

function functionname(canvas, isInit) {
    if(isInit) {
        // do magic on init
    } else {
        // do magic on de-init
    }
}

or

$('#myGrid').gridEditor({
    'custom_filter': function(canvas, isInit) {
        //...
    },
});

valid_col_sizes: Specify the column widths that can be selected using the +/- buttons

$('#myGrid').gridEditor({
    'valid_col_sizes': [2, 5, 8, 10],
});

Attribution

Grid Editor was heavily inspired by Neokoenig's grid manager