I want to change default two buttons pager to full number. Maybe this can be done with $parameters['datatable_options'], but where should I add this code?

Comments

xenolon’s picture

(Bump)
I would also like to know how to set the various options DataTables. For instance, how does one turn off pagination, or set multiple-column sorting, or save states, etc.

Outside of Drupal, one would just set these options in the initialization script, like:

$(document).ready(function() {
$('#example').dataTable( {
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false } );
} );

This doesn't appear to work if I place the initialization code in the template, and I don't see any options in the module, or views.

anschauung’s picture

StatusFileSize
new5.09 KB

This patch adds some of the dataTables initialization options to the style configuration menu. This hasn't been extensively tested, so any feedback would be helpful.

I added the features that I use most often, but "duellj made it pretty easy to add others with trivial modifications to the code, so let me know if you need a patch that adds another option before these features get added to the official versions.

anschauung’s picture

StatusFileSize
new14.09 KB

A better patch is attached here. Use this one instead.

xenolon’s picture

I get:
Hunk #1 FAILED at 178.
Hunk #2 FAILED at 241.

anschauung’s picture

At first glance, it looks like a problem with line endings or version mismatches. Are you running a Windows server and/or an older version of the Module? If the latter, try upgrading to the newest version and running the patch again.

duellj’s picture

Status: Active » Needs work

anschauung:

Thanks for the patch; I appreciate the work you've put into it. Most of the new configuration options look great, though there's still some work that needs to be done for the hidden/expandable options:

-Selecting a field as hidden/expandable shows all subsequent fields in the expanded box.

-Expanded box doesn't expand fully across all rows.

-I would like the expanded fields to be themable, hopefully using a theme() call.

-Class logic in datatables-view.tpl.php should be in template_preprocess_datatables_view().

If you want to split out the hidden/expandable code from the rest of the configuration options, I can commit that while we work on the former.

duellj’s picture

Status: Needs work » Needs review
StatusFileSize
new12.54 KB

Try out this patch and see if it works for you. I've made the expandable row themable, as well as moved all logic into template_preprocess_datatables_view() and datatables.js. If it's working correctly for you, I'll commit it.

anschauung’s picture

@duellj:

Works great so far, thanks! (And, a special thanks for fixing up the overall sloppiness in my expandable columns :)

I did end up adding some simple logic to Drupal.theme.prototype.datatablesExpandableRow so that views columns that have empty labels don't show up as "undefined" in the expanded columns. You might consider that to be a theme preference though.

duellj’s picture

Status: Needs review » Fixed

Thanks for the review, anschauung. I've committed the patch to both 6.x-1.x-dev and 7.x-1.x-dev branches.

The "undefined" label was actually a bug, thanks for finding it!

Note to self, collapsed fieldsets cause errors in views-3.x in D7: #893862: Collapsed fieldsets in plugin style options_form cause problems. Fix when issue is fixed.

anschauung’s picture

I've come across a few other minor nits as I was integrating this into a more complex site. These are probably too small to bother with a patch, so I'll just describe them here:

1) template_preprocess_datatables_view doesn't account for hidden-only (i.e. not expandable) columns. Something like the code below should do the trick:

    switch ($options['hidden_columns'][$field]) {
      case 'expandable':
        $datatable_options['bExpandable'] = TRUE;
        // ... and fall through, since expandable columns are also hidden
      case 'hidden':
        // Hidden or expandable columns get the bVisible init option set to false
        $column_options['bVisible'] = FALSE;
    }

2) dataTables 1.5.2 is referenced in hook_requirements, but 1.5.x doesn't work with Drupal.theme.prototype.datatablesExpandableRow since that version responds differently to rowData = datatable.fnGetData(row).

This could be fixed easily by upgrading to dataTables 1.6 or dataTables 1.7. Some people might not want to upgrade since newer versions of bAutoWidth miscalculates the width of large datatables in some edge cases, but referencing the newer version is probably the right way to go for most people.

3) The headers and labels on Drupal.theme.prototype.datatablesExpandableRow are off by one. I didn't notice this at first since I was using my own theme functions. Changing settings.aoColumnHeaders[index] to settings.aoColumnHeaders[index-1] is a quick and sloppy fix, or you could re-do the indexes. I believe this is related to the extra column that was added in the earlier Drupal.behaviors function

Thanks again for all your work on this!

duellj’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
Status: Fixed » Needs work

Reopening this until I get the items in #10 fixed.

1) Good catch, I'll add in the switch statement.

2) Good point, I should update the documentation to download dataTables 1.6. dataTables 1.7 depends on jquery 1.4, which even jquery_update isn't using yet (#685060: Get ready for 1.4).

3) This was fixed in CVS, if you do a checkout of 6.x-1.x-dev is it still happening?

Thanks again for all your help!

Note about bug from #9: actually it's a critical core bug #561858: [Tests added] Fix drupal_add_js() and drupal_add_css() to work for AJAX requests too by adding lazy-load to AJAX framework

duellj’s picture

Status: Needs work » Fixed

Fixed in CVS for both 6.x and 7.x branches

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • duellj committed 609d91a on 7.x-1.x, 7.x-2.x
    #869724 by anschauung, duellj: Adds additional options to view style,...
  • duellj committed 771d8fb on 7.x-1.x, 7.x-2.x
    #869724 by anschauung, duellj: Updates recommended dataTables library to...