I've just downloaded the latest sgrid - sgrid 7.x-1.x-dev (2011-Jun-15) and created a new view following instructions to use it. However when I click on save order it duplicates all the items in my view. I only have 2 photos in my view but when I click on save order it shows me 4 photos - duplicating the first two. When I click on save order again, it then shows me 8 photos and so on. I now have a lot of photos! I'm attaching a screenshot.

I'm using:
Drupal 7.0
Views 7.x-3.0-beta3
Chaos tool suite 7.x-1.0-alpha4
jquery_update 7.x-2.2
sgrid 7.x-1.x-dev (2011-Jun-15)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Countzero’s picture

Assigned: Unassigned » Countzero
Status: Active » Postponed (maintainer needs more info)

I can't see how my code could possibly make this happen.

My best guess is a weird interaction with another module, probably using Jquery.

Could you post a screenshot of the source of the relevant part of the page shown in Firebug, once you have duplicated the content three or four times ? The ids and classes of the added elements could help me diagnose the problem.

bmango’s picture

FileSize
604.8 KB

@Countzero Here's the firebug screenshot. Let me know if you need anything else.

Countzero’s picture

I was not able to reproduce the bug.

Some hints though :

- Your view seems to be special, as you say there are only two photos, but they are numbered sgrid_item_17 and sgrid_item_18 or the like, which seems to indicate there are some other rows in the view somewhere, which is strange. Something messes up the numbering. please disregard : numbering is nid based. i shouldn't do several things at the same time.
- This leads me to ask how the view is structured.
- The layout of the page seems to confirm you're using some module with slideshow functionalities. This could very well mess up something. Giving me the name of this module would be most helpfull to diagnose.
- A dump of the complete page source could be of use too.

bmango’s picture

FileSize
43.9 KB

Sorry for the delay in getting back to you. The view is structured very simply. I just added the image field, the format is set to sortable grid, and the format show is set to sgrid style.

You're right, I am using a slideshow module. It is views_slideshow 7.x-3.0-alpha1. I did try disable it to see if this would solve the problem, but it didn't make any difference.

I am also attaching a dump file for the whole page.

Thanks for taking the time to look at it!

Countzero’s picture

Perhaps something to try : you configured the view to display only one item per page, and with 60 rows.

Could you try to configure the same view, but with something like 4 items per row (in the row length parameter of the format) and with fewer items, just enough to fill a normal page like 20 or 30 ?

I'm not sure it will change anything, but it could give me some hints.

bmango’s picture

FileSize
24.49 KB
850.61 KB

I reset the number of items per row to 4. I also changed the filter to only include 4 photos (the original view only had two photos, it is just that they were repeating themselves). I am still, though, having the same problem. When I click on save order it duplicates the photos. So, I clicked on save order once, and now, instead of having 4 photos, I now have 8. Each photo has been duplicated. You can see this in the screenshot I have attached. This, is only in the view though, as in reality I still only have 4 photos.

I have also attached the code for the page.

Maybe, the best thing for to me to do, is to uninstall the sideshow module, delete the sortable grid view and recreate the view?

Countzero’s picture

Status: Postponed (maintainer needs more info) » Needs work

Well, I'm sorry, but I can't figure out what's happening on your setup.

Uninstalling and reinstalling everything would surely be worth a try, but I don't have a clue why it would work.

The fact you're the only one reporting the issue makes me lean towards the opinion something's messed up on your installation, but I can't be sure, of course.

Perhaps you could try deactivating all the JQuery oriented modules on the site and see which one causes the problem, provided this is the explanation.

Alternatively, you could send me a mail with an admin password to a copy of your site so I could investigate directly, but this is up to you.

Short of that, there's nothing I can do to help you further as of now.

bmango’s picture

@Countzero I did as you suggested and created a duplicate site. I've emailed you the details.

Countzero’s picture

Status: Needs work » Closed (fixed)

Problem sorted out with the user, probably caused by some particular situation. A clean reinstall of the module did the trick.

Closing.

donnellyjoe’s picture

Just wanted to chime in and say I had the same issue.

I had a total of three views set up. One view showing one category, another showing a another category, and a third view that displayed mixed results of the previous two categories. The duplication was only happening on the third view, where I had mixed results. I had applied a sortable page to all three views, so maybe the issue is happening because the sorting is doubling up.

I disabled and uninstalled the module and then re-enabled it and it appears to have fixed itself.

Great plugin FYI!

tomfilepp’s picture

definitely experiencing this as well. will have to try to uninstall and reinstall.

i assumed it was a question of making the view query only return distinct values, but that's not it.

it's not jquery related, since the markup is rendered at load, not by JS.

Countzero’s picture

Please let me know if a reinstall fixed your problem.

fonant’s picture

I have this, and it seems that the problem is caused if you have more than one view display using sgrid with the same nodes. This results in one line per view_display per node in the sgrid table, and thus duplication when this table is JOINed with the node NIDs.

In my situation I'd like to have a View with two displays (as blocks), one for administrators to drag-sort, and one for display of the sorted items. So I need the sort stored per-view, and not per-view-display. And the View SQL needs to select the view when picking the sort from the sgrid table.

fonant’s picture

Status: Closed (fixed) » Active

Yes, I can fix this (as a hack for my site) by not storing multiple rows in the sgrid table for each node, one for each sgrid view display. I've commented out the two lines that mention view_display in sgrid_save_order() and I no longer get duplication of nodes. But this means I can only have one sgrid sort order for the whole site.

The "proper" fix would be to make use of the view_display data when retrieving the views data rows, with a "WHERE sgrid.view_display = '%s'" and the current view display name as an argument. I can't easily see how to do this, sadly...

This is a valid bug, and will appear on any site that sorts the same nodes with more than one view_display.

fonant’s picture

OK, I think I have a fix that works for me:

1) Modify the sgrid table to store View name only, not including the display name. This means the sort order set in a view applies to all displays in that view. I re-named the database field "view" instead of "view_display". The sort saving code then changes to become:

function sgrid_save_order($view, $display, $reset = FALSE) {
  db_delete('sgrid')
    ->condition('view', $view)
    ->execute();
  if (! $reset) {
    foreach ($_GET['sgrid_item'] as $index => $name) {
      db_insert('sgrid')
        ->fields(array(
            'nid' => $name,
            'rank' => $index,
            'view' => $view,
          )
        )
      ->execute();
    }
  }
  print t("Order saved");
}

2) Add this to the bottom of sgrid.views.inc

function sgrid_views_query_alter(&$view, &$query) {
 if (in_array('node_sgrid', array_keys($query->table_queue))) {
  $query->add_where(0, db_or()->condition('sgrid.view', $view->name, '=')->condition('sgrid.rank', NULL, 'IS NULL'));
  }
}

This adds an additional "WHERE" clause to any query that involves the node_sgrid join, selecting only sgrid rows that are for the current view.

There may be a neater way to do this with a custom handler, but this works.

MrPaulDriver’s picture

The fix at #15 is not working for me.

The different views are displayed but save and reset do not work.

Shame because this is a legitimate bug

fonant’s picture

Check your Drupal watchdog logs for database error messages.

Did you change the sgrid table to have "view" instead of "view_display" for the third column?

MrPaulDriver’s picture

No I haven't viewed the Watchdog logs. What I did do was completely uninstall the module, before installing the patched version. I assume this would have taken care of the database when installing. Was I wrong about this?

fonant’s picture

Yes, a complete uninstall and reinstall should delete and then re-create the table.

The code that does the "Save" and "Reset" work is very simple, consisting mainly of database queries. So the watchdog log might have a database query error that would tell us what was broken.

MrPaulDriver’s picture

I'll take a closer look. Thank you

lathan’s picture

#work-around: I had the exact same issue here the quick fix is delete all the data in the sgrid table. This then gets everything working again nicely but you loose all your old sorts.

#problem: What happens is that if you have sort data in the table and then change the view display, the old data from the previous display is included in the loaded view results. Then we one saves again those then get "transformed" into new indexes with the correct suffix and added into the DB.

This module needs some sort of trigger / update happening when view displays are changed, or at worst a total flush of data with a warning.

tmmm’s picture

Hi, I have the same problem here.

After sorting and saving a view, it duplicates the entries so I've got the items up to four times. My settings should be right: the format is "Sortable Grid", the Row Style is "Sgrid-Style" and the sort criteria is set to: "Sortable Grid: Rank (asc)".

I've tried the fix from #15 but I got the PDO Exception: "Column not found" and the two buttons aren't working anymore.

I also tried to uninstall and reinstall the module, but it doesn't have any positive effect.

Do you have any hints for me to solve the problem?

Without the Problem the Module must be awesome!

fonant’s picture

@tmmm - if you're getting "Column not found" then the database probably still has the original "view_display" column instead of the "view" column required by my fix. You could try uninstalling (uninstall, not just deactivate) and re-installing after adding the new code, or you could manually change the column name in the database.

tmmm’s picture

Thank you for your quick reply fonant!

After deactivating, deinstalling and reinstalling the module I've renamened the "view-display" column in the database manually. The buttons are saving and reseting the order without any "Column not found" error, but I got duplicated items like before the fix.

edit: It seems like the error only shows up when I disable the feature "Display all values in the same row" in views. If this checkbox is enabled saving and sorting works fine. But i can't sort the items which are in the same row.