Hi,

Thanks for a great module. Just what I needed to effortlessly sort a grid view of Project nodes (custom content type: Title, Body + image). My site is bilingual and uses i18n. Multilingual support is "Enabled, with translation". That means that each English node is coupled with a French translation node in a translation set.

Problem: ordering the nodes with sgrid in English and saving works as expected (the view displays the nodes in the saved order). But this order is lost when switching to French with the language switcher block. Reordering from the French side and saving works as expected, French wise. Unfortunately, the order saved in the French interface is lost again when switching to English.

Views display details are attached.

CommentFileSizeAuthor
sGrid display.png306.4 KBbisonbleu
Grid display.png296.32 KBbisonbleu

Comments

Countzero’s picture

Title: "Sortable Grid: Rank" is not maintained across translation set...? » Integrate sorting with language features
Assigned: Unassigned » Countzero
Category: bug » feature
Status: Active » Needs work

You're absolutely right : internationalization wasn't taken into account at first.

You're the first one to ask for this functionality, but it's definitely needed.

I'll try to make a corrrected release before next week with this correction, which shouldn't require too much work.

Thanks for your interest in the module.

bisonbleu’s picture

Merci!

May I make a suggestion?

In an ideal world, sorting in one language would define the default sort that would automatically apply to all languages. Bonus: add an language specific option to override the default sort.

Renaud

Countzero’s picture

You may, but I'm not sure what you mean about the option.

You think the option should go on the sort form ?

As I understand it, the language parameter should be transparent to the user don't you think ? It's some kind of context option ...

But perhaps I'm misunderstanding your point, so feel free to give me more clues.

bisonbleu’s picture

About the initial sort becoming the de facto default sort for all languages. Let's say I have a multilingual website with 10 languages, sorting once for all languages would be nice (otherwise one would have to repeat the sort 10 times - not fun).

What I meant by bonus was that it would be nice to be able have a different sort order depending on the language. For example: all languages except French > node order = [1,2,3,4] and French > node order = [4,3,2,1]. But this could also be achieved by adding a second display for the French language, right?

Countzero’s picture

OK, I understand better and have to give it some thought.

Unfortunately, I didn't have time to work on the module these days : too many things going on at the same time.

So be sure the principle of the feature is acted, but the delay might stretch a little/big bit.

vindi’s picture

Issue summary: View changes

Just a hint: modify sgrid.module:

function sgrid_save_order($view, $display, $reset = FALSE) {

    // Set key depending on
    // * View
    // * Current view display
    // * Language
    // * (optionally) Domain
    global $language;
    $key = $view . '_' . $display . '_' . $language->language;
    
    if (function_exists('domain_get_domain')) {
        $domain = domain_get_domain();
        $key .= '_' . $domain['domain_id'];
    }
    
    // Delete existing order
    db_delete('sgrid')
        ->condition('view_display', $key)
        ->execute();
        
    // Set new order
    if (!$reset) {
        foreach ($_GET['sgrid_item'] as $index => $name) {
            db_insert('sgrid')
                ->fields(array(
                    'nid' => $name,
                    'rank' => $index,
                    'view_display' => $key,
                )
            )
            ->execute();
        }
    }
    print t("Order saved");
}

function sgrid_views_query_alter(&$view, &$query) 
{
    if ($view->plugin_name == 'sgrid') {
        
        // Generate key
        global $language;
        $key = $view->name . '_' . $view->current_display . '_' . $language->language;
        if (function_exists('domain_get_domain')) {
            $domain = domain_get_domain();
            $key .= '_' . $domain['domain_id'];
        }
        
        $query->add_where(0, db_or()
            ->condition('sgrid.view_display', $key, '=')
            ->condition('sgrid.view_display', null, 'IS NULL')
        );
    }
}

And change references to '/save_order/' in sgrid js to call a proper language:

var save_url = '/' + $('html').attr('lang') + '/save_order/';