Added custom sorting to table sorter

This commit is contained in:
Mark McDowall 2013-02-16 17:16:37 -08:00
parent 6f359cb4db
commit c55099ce5a
6 changed files with 91 additions and 7 deletions

View File

@ -213,6 +213,7 @@
<Content Include="_backboneApp\JsLibraries\require.js" />
<Content Include="_backboneApp\Mixins\backbone.ajax.js" />
<Content Include="_backboneApp\Mixins\backbone.marionette.templates.js" />
<Content Include="_backboneApp\Mixins\tablesorter.extensions.js" />
<Content Include="_backboneApp\Routing.js" />
<Content Include="_backboneApp\JsLibraries\backbone.modelbinder.js" />
<Content Include="_backboneApp\AddSeries\New\AddNewSeriesTemplate.html" />

View File

@ -75,6 +75,7 @@
<script src="/_backboneApp/JsLibraries/backbone.mutators.js"></script>
<script src="/_backboneApp/JsLibraries/backbone.marionette.js"></script>
<script src="/_backboneApp/JsLibraries/jquery.tablesorter.js"></script>
@*
<script src="/_backboneApp/JsLibraries/jquery.tablesorter.bootstrap.js"></script>
*@
@ -82,6 +83,7 @@
<script src="/_backboneApp/Mixins/backbone.marionette.templates.js"></script>
<script src="/_backboneApp/Mixins/backbone.ajax.js"></script>
<script src="/_backboneApp/Mixins/tablesorter.extensions.js"></script>
<script data-main="/_backboneApp/app" src="/_backboneApp/JsLibraries/require.js"></script>
<script src="/_backboneApp/Routing.js"></script>

View File

@ -0,0 +1,49 @@
$.tablesorter.addParser({
// set a unique id
id: 'title',
is: function (s) {
// return false so this parser is not auto detected
return false;
},
format: function (s) {
// format your data for normalization
return s.match(/title="(.*?)"/)[1].toLowerCase();
},
// set type, either numeric or text
type: 'text'
});
$.tablesorter.addParser({
// set a unique id
id: 'date',
is: function (s) {
// return false so this parser is not auto detected
return false;
},
format: function (s) {
// format your data for normalization
var match = s.match(/data-date="(.*?)"/)[1];
if (match === '')
return Date.create().addYears(100).format(Date.ISO8601_DATETIME);
return match;
},
// set type, either numeric or text
type: 'text'
});
$.tablesorter.addParser({
// set a unique id
id: 'innerHtml',
is: function (s) {
// return false so this parser is not auto detected
return false;
},
format: function (s) {
// format your data for normalization
return $(s).get(0).innerHTML;
},
// set type, either numeric or text
type: 'text'
});

View File

@ -31,14 +31,44 @@ define(['app', 'Quality/QualityProfileCollection', 'Series/SeriesItemView'], fun
if(!this.tableSorter && this.collection.length > 0)
{
this.tableSorter = this.ui.table.tablesorter({
textExtraction: function (node) {
return node.innerHTML;
},
sortList: [[1,0]],
headers: {
0: {
sorter: 'title'
},
1: {
sorter: 'innerHtml'
},
5: {
sorter: 'date'
},
6: {
sorter: false
},
7: {
sorter: false
}
}
});
this.tableSorter = this.ui.table.tablesorter();
this.ui.table.find('th.header').each(function(){
$(this).append('<i class="icon-sort pull-right">');
});
this.ui.table.bind("sortEnd",function() {
this.ui.table.bind("sortEnd", function() {
$(this).find('th.header i').each(function(){
$(this).remove();
});
$(this).find('th.header').each(function () {
if (!$(this).hasClass('headerSortDown') && !$(this).hasClass('headerSortUp'))
$(this).append('<i class="icon-sort pull-right">');
});
$(this).find('th.headerSortDown').each(function(){
$(this).append('<i class="icon-sort-down pull-right">');
});
@ -47,7 +77,7 @@ define(['app', 'Quality/QualityProfileCollection', 'Series/SeriesItemView'], fun
$(this).append('<i class="icon-sort-up pull-right">');
});
});
}
}
else
{
this.ui.table.trigger('update');

View File

@ -42,7 +42,7 @@
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<CodeAnalysisRuleSet>BasicCorrectnessRules.ruleset</CodeAnalysisRuleSet>
<IntermediateOutputPath>C:\Users\Mark.McDowall\AppData\Local\Temp\vs83FB.tmp\x86\Debug\</IntermediateOutputPath>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Debug\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -52,7 +52,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<IntermediateOutputPath>C:\Users\Mark.McDowall\AppData\Local\Temp\vs83FB.tmp\x86\Release\</IntermediateOutputPath>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Release\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
@ -71,6 +71,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs1A55.tmp\x86\Mono\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">

View File

@ -42,7 +42,7 @@
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
<CodeAnalysisRuleSet>BasicCorrectnessRules.ruleset</CodeAnalysisRuleSet>
<IntermediateOutputPath>C:\Users\Mark.McDowall\AppData\Local\Temp\vs8003.tmp\x86\Debug\</IntermediateOutputPath>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Debug\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
@ -52,7 +52,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<IntermediateOutputPath>C:\Users\Mark.McDowall\AppData\Local\Temp\vs8003.tmp\x86\Release\</IntermediateOutputPath>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Release\</IntermediateOutputPath>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>NzbDrone.ico</ApplicationIcon>
@ -71,6 +71,7 @@
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<IntermediateOutputPath>C:\Users\Mark\AppData\Local\Temp\vs167E.tmp\x86\Mono\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="Autofac, Version=2.6.3.862, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">