alfajango / jquery-dynatable

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

Adding the originalTR to the record object #230

Open DotSlashNatalie opened 8 years ago

DotSlashNatalie commented 8 years ago

I made this change in my project because I added a CSS class to certain rows (such as rows to indicate an error). This change allows you to view or access the original tr so that you can copy the CSS class that was applied to it and apply the CSS class to the new tr generation. I'm sure there are better ways to achieve this - but this was my quick patch to get what I needed working.

Example:

function defaultRowWriter(rowIndex, record, columns, cellWriter) {
    var tr = '';

    // grab the record's attribute for each column
    for (var i = 0, len = columns.length; i < len; i++) {
      tr += cellWriter(columns[i], record);
    }

    return '<tr class="' + record.originalTR[0].className + '">' + tr + '</tr>';
  };
JangoSteve commented 8 years ago

Thanks for submitting this. I like the idea, but this could potentially cause a large balloon in memory usage for tables with a lot of rows. To pull this in, I'd think about only copying the class name if it exists for the row, and only doing so if a config option to copy row classes is enabled (i.e. add a new config option and make it false by default).

DotSlashNatalie commented 8 years ago

That makes sense. I'll make the modifications in the near future. I've just been handed a big project so I won't be able to make the change for awhile. Feel free to poke this PR if you think I forgot about this.

DotSlashNatalie commented 8 years ago

Is the latest commit what you were thinking of?

Here is a sample: http://jsfiddle.net/904zebn5/1/