Code Monkey home page Code Monkey logo

dolly.js's Introduction

Dolly.js - Clone your tables easily

Dolly.js is a simple and generic jQuery UI widget that adds excel-like cloning functionality to your tables. It works with any tabular structure (not only semantic html tables) and does not make any assumptions about the underlying data structure. It handles the UI part of cloning only - the implementation of business cloning logic is left to the widget's users.

Usage

Call the dolly method on every table cell that should have cloning functionality. Then listen on cloned event to handle the data-related part of cloning.

$('td').dolly({
  cloned: function (event, ui) {
    console.log(this, "has been cloned " + ui.cloneX + " cells horizontally and " + ui.cloneY + " vertically.");
  }
});

You can find more elaborate examples in the examples directory.

Options

allowDiagonalSelection

Enable possiblity to select cells in an area. Defaults to false. Example:

$(cell).dolly({
  allowDiagonalSelection: true,
  rowSelector: 'div.row',
  cellSelector: 'div.cell'
});

will make possible to select a group of cells like this:

cloning an area of cells

rowSelector

jQuery selector for elements that should be considered the rows of the table. Defaults to "tr". Example:

$(cell).dolly({
  rowSelector: 'div.row',
  cellSelector: 'div.cell'
});

cellSelector

jQuery selector for elements that should be considered the cells of the table. Defaults to "td". Example:

$(cell).dolly({
  rowSelector: 'div.row',
  cellSelector: 'div.cell'
});

boxStyle

Object with custom CSS styles assigned to the selection box displayed when user clones cells. For example:

$(cell).dolly({
  boxStyle: {
    "background-color": "rgba(255, 0, 0, 0.2)",
     border: "3px red dotted"
  }
});

will result in a selection box like this:

red clone box

You can also style this with CSS dolly-box class.

handleStyle

Object with custom CSS styles assigned to the handle of the cloning box.

$(cell).dolly({
  handleStyle: {
    width: "0",
    height: "0",
    "background-color": "transparent",
    "border-top": "7px solid transparent",
    "border-left": "7px solid transparent",
    "border-bottom": "7px solid black",
    "border-right": "7px solid black",
    }
  }
});

will result in a triangular handle like this:

triangular dolly handle

You can also style this with CSS dolly-handle class.

Events

In all event callbacks this is bound to the origin HTML cell element.

Contents of ui object

The ui object is passed as the second argument to every callback. It contains:

  • originX - position of cell in row that triggered the event (0-indexed).
  • originY - position of row containing cell that triggered the event (0-indexed).
  • cloneX - number of cells selected for cloning horizontally. Negative values stand for cloning to the left, positive to the right.
  • cloneY - number of cells selected for cloning vertically. Negative values stand for cloning up, positive for cloning down.

cloned

Triggered whenever user requests cloning of a cell. You can pass a callback during dolly initialization like this:

$(cell).dolly({
  cloned: function (event, ui) {
    ...
  }
});

or listen on dollycloned event:

$(cell).dolly().on('dollycloned', function (event, ui) {...});

selected

Triggered whenever the size of selection box changes. This does not mean a clone request, just a user moving the handle. After user releases the handle, cloned event is triggered.

Once again you can pass a callback directly or listen on dollyselected event.

dolly.js's People

Contributors

rafaelcaricio avatar kustosz avatar szynszyliszys avatar rusilko avatar

Stargazers

简律纯 avatar Tomi Häsä avatar Marco Naylon avatar Hanna Seweryn avatar TheCreation avatar Matt Zimmermann avatar Daniel Queiroz Santos avatar Pantelis Koukousoulas avatar  avatar Pedro Coutinho avatar Jonathan Barratt avatar  avatar Paing Pyi avatar Beata Mosór-Szyszka avatar Todd Bashor avatar Evo Stamatov avatar Dr. Kat avatar Ethan avatar tom zhou avatar  avatar Robert Wade avatar Joohun, Maeng avatar  avatar  avatar Stanisław Chmiela avatar Marcos Junior avatar Aniket Pant avatar Jon B avatar Marco Mocca avatar Chris Edwards avatar Tomas Kartasovas avatar Igor Petrov avatar Jiri Melcak avatar Iván Olivares R. avatar Marcin avatar Stephen Kaiser avatar Steven Marcus avatar  avatar Jason Kulatunga avatar send2vinnie avatar Yuan Zhu avatar Geoff avatar  avatar timelyportfolio avatar Erick Patrick avatar mauricio gamarra avatar Chris Witko avatar Luis Monteiro avatar Jan Roudaut avatar M Haidar Hanif avatar Viktor Vasilev avatar  avatar Gerardo Lisboa avatar Vorleak Chy avatar Sascha avatar  avatar 唐睿 avatar Kenn Ejima avatar kayak avatar Marcos Sader avatar Val Packett avatar Alexander Khlebnikov avatar Andreas Sippl avatar  avatar Sebastian Troć avatar A Porat avatar Kasia Szawan avatar Mohammed Irfan avatar Piotr avatar Grzegorz Świrski avatar Mateusz Wróbel avatar Maciej Ciemborowicz avatar Mirek Wozniak avatar Krzysztof Knapik avatar Phillip Boksz avatar Tomasz Giereś avatar Artur Trzop avatar

Watchers

Paul Klipp avatar Basia Madej-Romaniuk avatar Anna Ślimak avatar tom zhou avatar send2vinnie avatar  avatar Maria avatar Julia Jacobs avatar Hanna Seweryn avatar James Cloos avatar Daniel Queiroz Santos avatar Tomasz Giereś avatar  avatar  avatar  avatar Małgorzata avatar Dawid Cichuta avatar Will Griffiths avatar Katarzyna Kurzyńska avatar Lunar Logic Dev avatar Kasia Szawan avatar  avatar  avatar Beata Mosór-Szyszka avatar Marta Połeć avatar Marcin Drozd avatar Paulina avatar  avatar Wiktor Tendera avatar Aleksandra Szczurek avatar Anna Lesniak avatar Jakub Rupinski avatar Radosław Wieczorek avatar Kazimierz Szołtysik avatar  avatar Emiliana Guzik avatar Anna Olak avatar Iwona Tryka avatar  avatar

dolly.js's Issues

Clone a specific column

Good day,

Hoping I can ask this question here. My table contains a number of columns and I'm looking to call Dolly only on 2 columns. Is this possible, and could you provide an example of how I would do it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.