Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Sorting the surveys on the front page

More
9 years 3 months ago #137076 by silver
Good morning,
how can i sort the surveys on the front page of my LimeSurvey?

I have 10 surveys which i wanna sort by myself.
They begin with 1, 2, 3... and so i wanna sort it.

Thank you!
The topic has been locked.
More
9 years 3 months ago #137092 by tpartner
LimeSurvey version?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 3 months ago #137096 by silver
160526, i´ve solved it by sorting it directly in the database.
The topic has been locked.
More
9 years 3 months ago #137099 by tpartner
For those who don't have direct access to the database, adding this to template.js will sort the survey list in version 2.5:

Code:
$(document).ready(function() {  
 
  if($('.surveys-list').length > 0) {
 
    // Build an array of survey titles
    var titles = [];
    $('a.surveytitle').each(function(i) {
      titles.push($(this).text());
    });
 
    // Sort the titles array
    titles.sort();
 
    // Insert the survey links in sorted order
    $(titles).each(function(i) {
      var thisText = this;
      $('a.surveytitle').filter(function() {
        return $(this).text() == thisText;
      }).closest('li').appendTo($('.surveys-list'));
    });
  }
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 7 months ago #148376 by sjsls2016
Hi there. I tried doing this one but the surveys on the public page does not change. I just copy and pasted the script at template.js , I am using Version 2.51.4+160908...
Please help me if I missed something. Thanks.
The topic has been locked.
More
8 years 7 months ago #148428 by tpartner
Did you set the modified template as "Default template:" in Global settings?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 4 months ago #154562 by oleggorfinkel
Hi Tony,

I have the same problem -- I have added the script to template.js, but the survey list on the front page is still not sorted. I do have the template set as Default -- it's the same one I've always used.

I am on Version 2.63.1+170305.

Hope you can help... Thanks!

Oleg G.
The topic has been locked.
More
8 years 4 months ago #154614 by tpartner
Can you provide a link to the page?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • New Member
  • New Member
More
8 years 4 months ago #154699 by LouisGac
Replied by LouisGac on topic Sorting the surveys on the front page
In coming LS3 release, you'll be able to redesign the survey list inside template files using twig:

github.com/LimeSurvey/LimeSurvey/blob/de...out_survey_list.twig
The topic has been locked.
More
8 years 3 months ago #154742 by oleggorfinkel
Here is the link to the page: apuv.tentokai.com (screen capture attached). You'll see that the surveys are listed out of order, despite the fact that the template.js file (attached) has been modified.

Oleg G.
The topic has been locked.
More
8 years 3 months ago #154754 by tpartner
I don't see the script in the template.js file for the linked page - apuv.tentokai.com/tmp/assets/6412d865/scripts/template.js

Are you sure that you have activated the modified template as "Default template"?



Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 3 months ago #154755 by tpartner
Additionally, it looks like the code above is now obsolete - use the code from this post - www.limesurvey.org/forum/can-i-do-this-w...-survey-order#153196

Code:
$(document).ready(function(){  
 
 
  if($('div.survey-list').length > 0) {
 
    // Create an array of survey titles
    var surveyTitles = [];
    $('div.survey-list a.surveytitle').each(function(i) {
      $(this).attr('data-sid', $(this).attr('href').split('index.php/')[1].split('?')[0]);
      $(this).attr('data-name', $.trim($(this).text())+' - '+$(this).attr('href').split('index.php/')[1].split('?')[0]);
      surveyTitles.push($(this).attr('data-name'));        
    });
 
    // Sort the titles
    surveyTitles.sort();
 
    // Insert the survey links in sorted order
    $(surveyTitles).each(function(i, val) {
      var thisLink = $('div.survey-list a.surveytitle').filter(function(e) {
        return $(this).attr('data-name') == val;
      });  
      $('div.survey-list > .container > .row').append($(thisLink).parent());      
    });
 
    // Handle the public stats links
    $('div.survey-list a.view-stats').each(function(i) {
      $(this).attr('data-sid', $(this).attr('href').split('statistics_user/')[1].split('?')[0]);
      $(this).parent().insertAfter($('div.survey-list a.surveytitle[data-sid="'+$(this).attr('data-sid')+'"]').parent());
    });
 
    // Fix up the dividers
    $('div.survey-list > .container > .row > .col-xs-12, div.survey-list > .container > .row > .col-xs-2').removeClass('vertical-divider right');
    var dividerClass = 1;
    $('div.survey-list > .container > .row > .col-xs-12, div.survey-list > .container > .row > .col-xs-2').each(function(i) {
      dividerClass++;
      if(dividerClass % 2 == 0) {
        $(this).addClass('vertical-divider right');
      }
    });
 
  }
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 3 months ago - 8 years 3 months ago #154770 by oleggorfinkel
Hi Tony,

Yes, the template is, in fact, selected as default (see attached image) in General settings.

I have added the new code you provided in your other message to template.js (attached).

This modified template.js file with the sorting code is sitting in upload/templates/AtencionPlenaUV/scripts (see attached screenshot). I don't understand why it's not being loaded.

Cheers...
Oleg.

Oleg G.
Last edit: 8 years 3 months ago by oleggorfinkel.
The topic has been locked.
More
8 years 3 months ago #154785 by tpartner
Try bypassing the assets manager so files are loaded directly from the template directory.

In /application/config/config.php, set debug to 1.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 3 months ago #154796 by oleggorfinkel

tpartner wrote: Try bypassing the assets manager so files are loaded directly from the template directory.

In /application/config/config.php, set debug to 1.


Just did -- no change... :(

Oleg G.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose