0

I'm trying to build a custom library for my table, I want to add an option where for each column (th) I may be able to defined their width depends to what I declared. For example I only need to define the width of the first and second column (th) and I have 8 columns, there rest of the column should have width.

My sample snippets inside my table prototype:

init: function (el, options) {
     column: {
       width: [20, 200, 500]
     }
}

I am not really sure how to, since I'm starting to learn javascript. For now I'm just up to adding the width, sooner or later I'll be adding more options inside the column, like color etc.

Additional information: I want pure JavaScript without using other library (jQuery) to my library.

  • Not sure what it is you're after but maybe the following can help you when defining a certain type of object: http://stackoverflow.com/questions/16063394/prototypical-inheritance-writing-up/16063711#16063711 – HMR Oct 26 '14 at 15:26
  • @HMR let's see what I can learn in the reference you gave. :) –  Oct 26 '14 at 15:29

1 Answers1

0

Model-wise you probably want something like:

{
    columns: [ {
        label: "Foo",
        width: 50   // px
    }, {
        label: "Bar",
        width: 100  // px
    }, {
        label: "Baz",
        width: "*"
    } ]
}

instead of

{
    column_widths: [ 50, 100, "*" ]
    column_labels: [ "Foo", "Bar", "Baz" ]
}

The "*" would translate to a column with no defined width so the browser will decide how wide it is. Whether that is desirable or not is up to you.

Halcyon
  • 57,230
  • 10
  • 89
  • 128