Welcome to the LimeSurvey Community Forum

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

Sorting the surveys on the front page

  • silver
  • silver's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 9 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #137092 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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.
  • silver
  • silver's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 9 months ago #137096 by silver
Replied by silver on topic Sorting the surveys on the front page
160526, i´ve solved it by sorting it directly in the database.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 9 months ago #137099 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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
7 years 1 month ago #148376 by sjsls2016
Replied by sjsls2016 on topic Sorting the surveys on the front page
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 1 month ago #148428 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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
6 years 10 months ago #154562 by oleggorfinkel
Replied by oleggorfinkel on topic Sorting the surveys on the front page
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago #154614 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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
  • Visitor
  • Visitor
6 years 10 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
6 years 10 months ago #154742 by oleggorfinkel
Replied by oleggorfinkel on topic Sorting the surveys on the front page
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago #154754 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 10 months ago #154755 by tpartner
Replied by tpartner on topic Sorting the surveys on the front page
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.

Lime-years ahead

Online-surveys for every purse and purpose