alfajango / jquery-dynatable

A more-fun, semantic, alternative to datatables
http://www.dynatable.com
Other
2.77k stars 361 forks source link

declarative columns? #159

Open timc13 opened 9 years ago

timc13 commented 9 years ago

Is there anyway to declare columns besides writing html ? It looks like settings.table.columns should allow that, but the DomColumns.init function (line 440) clears any columns that are passed in!

Is there a good reason for this? You should be able to get them from the html table or from the settings.table object

CaptainCannabis commented 9 years ago

You can push the new data into the "orginalRecords"-set. After that run the "process" method to render the new table

function addRow(table,DS){ table.data('dynatable').settings.dataset.originalRecords.push(DS); table.data('dynatable').process(); }

timc13 commented 9 years ago

sorry, I don't follow - what does originalRecords have to do with columns? My problem is that I cannot initialize dynatables because I don't have any column cells declared in my table (I'd like to pass them in the settings object). This is the message:

Couldn't find any columns headers in 'thead tr th,td'. If your header row is different, specify the selector in the table: headRowSelector option.

JangoSteve commented 9 years ago

@timc13 This is a known feature missing from dynatable and definitely one I'd like to add. Ideally, you'd be able to call dynatable with something like this:

$("#my-table").dynatable({
  table: {
    columns: ["Name", "Email"]
  }
});

And dynatable would also create the header row of columns for you too.

This doesn't work yet though and hasn't been implemented.

shaynewang commented 9 years ago

For the sake of others maybe run into the same error. I got this error when I create column header with jquery on the run, with no initial header. The problem was that when I created the header I used this schema : <table> <thead> <th>col1</th> <th>col2</th> <th>col3</th> </thead> ...</table> However, dynatable maybe looking for the<tr></tr>tag. So after I predefined the table as <table> <thead> <tr></tr> </thead> ...</table>

then $("#my_table>thead>tr").append("<th> ... </th>") works