Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buttons implemented (#185) #186

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Mvc.JQuery.DataTables.Common/DataTableConfigVm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public string ColumnDefsString

public bool TableTools { get; set; }

public bool Buttons { get; set; }

public bool AutoWidth { get; set; }

public JToken SearchCols
Expand Down Expand Up @@ -96,6 +98,8 @@ public string Dom
str += "C";
if (this.TableTools)
str += "T<\"clear\">";
if (this.Buttons)
str += "B";
if (this.ShowPageSizes)
str += "l";
if (this.ShowFilterInput)
Expand Down
3 changes: 2 additions & 1 deletion Mvc.JQuery.DataTables.Tests/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net451" />
<package id="Microsoft.SqlServer.Compact" version="4.0.8876.1" targetFramework="net451" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net451" />
<package id="NUnit" version="3.6.1" targetFramework="net451" />
<package id="NUnit" version="3.13.2" targetFramework="net451" />
<package id="NUnitTestAdapter.WithFramework" version="2.0.0" targetFramework="net451" />
</packages>
2 changes: 2 additions & 0 deletions Mvc.JQuery.Datatables.Example/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public ActionResult Index()
vm.ColVis = true;
vm.ShowVisibleColumnPicker = true; //Displays a control for showing/hiding columns

//Enable Buttons
vm.Buttons = true;

//Localizable
if (Request.QueryString["lang"] == "de")
Expand Down
14 changes: 12 additions & 2 deletions Mvc.JQuery.Datatables.Example/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SomeController : Controller
<p>
and render the partial (see <a href="https://github.com/mcintyre321/mvc.jquery.datatables/tree/master/Mvc.JQuery.DataTables.Example/Views/Home/Index.cshtml">example</a>)

<pre class="highlight">
<pre class="highlight">
//include these scripts to use standard features
&lt;script type="text/javascript" src="//cdn.datatables.net/1.10.0/js/jquery.dataTables.js">&lt;/script>
&lt;link rel="stylesheet" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css" />
Expand All @@ -51,14 +51,24 @@ public class SomeController : Controller
&lt;script type="text/javascript" src="/Content/jquery-datatables-column-filter/jquery-ui-timepicker-addon.js">&lt;/script>
&lt;link rel="stylesheet" href="/Content/jquery-datatables-column-filter/jquery-ui-timepicker-addon.css" />

//and these if you want to use TableTools (export buttons)
//and these if you want to use TableTools (export buttons, deprecated with Flash). Use Buttons for new version.
&lt;script type="text/javascript" src="//cdn.datatables.net/tabletools/2.2.1/js/dataTables.tableTools.min.js">&lt;/script>
&lt;link rel="stylesheet" href="//cdn.datatables.net/tabletools/2.2.1/css/dataTables.tableTools.css" />

//And these if you want to use column visibility
&lt;link rel="stylesheet" href="//cdn.datatables.net/colvis/1.1.1/css/dataTables.colVis.css" />
&lt;script type="text/javascript" src="//cdn.datatables.net/colvis/1.1.1/js/dataTables.colVis.min.js">&lt;/script>

//And these if you need buttons, note the button colVis is included
&lt;link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" /&gt;
&lt;script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.colVis.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"&gt;&lt;/script&gt;

var dataTablesConfigVm = dataTablesConfigVmHtml.DataTableVm("table-id", (HomeController h) => h.GetUsers(null))
//set options on the config here, see <a href="https://github.com/mcintyre321/mvc.jquery.datatables/tree/master/Mvc.JQuery.Datatables.Example/Views/Home/_ExampleTable.cshtml">example here</a>

Expand Down
14 changes: 11 additions & 3 deletions Mvc.JQuery.Datatables.Example/Views/Home/_ExampleTable.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
<script type="text/javascript" src="//cdn.datatables.net/1.10.11/js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/1.10.0/css/jquery.dataTables.css" />
<!-- table tools (csv export etc) https://datatables.net/extensions/tabletools -->
<script type="text/javascript" src="//cdn.datatables.net/tabletools/2.2.1/js/dataTables.tableTools.min.js"></script>
<link rel="stylesheet" href="//cdn.datatables.net/tabletools/2.2.1/css/dataTables.tableTools.css" />

<script type="text/javascript" src="/Content/jquery-datatables-column-filter/jquery-ui-timepicker-addon.js"></script>
<link rel="stylesheet" href="/Content/jquery-datatables-column-filter/jquery-ui-timepicker-addon.css" />
Expand All @@ -22,11 +20,21 @@
<link rel="stylesheet" href="//cdn.datatables.net/colvis/1.1.1/css/dataTables.colVis.css" />
<script type="text/javascript" src="//cdn.datatables.net/colvis/1.1.1/js/dataTables.colVis.min.js"></script>

<!-- Imports needed for Buttons to work -->
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" />
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jszip/2.5.0/jszip.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.colVis.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>

@{

//var vm = Html.DataTableVm("table-id", (HomeController h) => h.GetUsers(null));
var vm = Model;

}

<script type="text/javascript">
Expand Down
10 changes: 8 additions & 2 deletions Mvc.JQuery.Datatables.Templates/Views/Shared/DataTable.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@
{
options["oTableTools"] = new JRaw("{ 'sSwfPath': '//cdn.datatables.net/tabletools/2.2.1/swf/copy_csv_xls_pdf.swf' }");
}
if (Model.Buttons)
{
options["buttons"] = new JRaw("[ 'copy', 'csv', 'excel', 'print', 'pdf' ]");
}


options["fnServerData"] = new JRaw(
"function(sSource, aoData, fnCallback) { " +
"function(sSource, aoData, fnCallback) { " +
" var ajaxOptions = { 'dataType': 'json', 'type': 'POST', 'url': sSource, 'data': aoData, 'success': fnCallback }; " +
(Model.AjaxErrorHandler == null ? "" : ("ajaxOptions['error'] = " + Model.AjaxErrorHandler) + "; ") +
" $.ajax(ajaxOptions);" +
Expand All @@ -85,7 +91,7 @@
{
options["fnDrawCallback"] = new JRaw(Model.DrawCallback);
}

}

var dt = $table.dataTable(@Html.Raw(options.ToString(Formatting.Indented)));
Expand Down
12 changes: 9 additions & 3 deletions Mvc.JQuery.Datatables.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26228.10
# Visual Studio Version 16
VisualStudioVersion = 16.0.31402.337
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.JQuery.DataTables.Common", "Mvc.JQuery.DataTables.Common\Mvc.JQuery.DataTables.Common.csproj", "{BFD9EA5A-FE3A-4CE2-9C09-B9E78CE208EE}"
EndProject
Expand All @@ -10,12 +10,15 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.JQuery.DataTables.AspNetCore", "Mvc.JQuery.DataTables.AspNetCore\Mvc.JQuery.DataTables.AspNetCore.csproj", "{59A635A9-751E-4457-BC54-65F85A9AE317}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvc.JQuery.DataTables.Example", "Mvc.JQuery.DataTables.Example\Mvc.JQuery.DataTables.Example.csproj", "{305FA463-4D61-4E28-8A4B-55A1E74D1BD7}"
ProjectSection(ProjectDependencies) = postProject
{8DA3D5E6-D714-40C3-B6CB-E88D852C5175} = {8DA3D5E6-D714-40C3-B6CB-E88D852C5175}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvc.JQuery.DataTables.Tests", "Mvc.JQuery.DataTables.Tests\Mvc.JQuery.DataTables.Tests.csproj", "{11A04151-EF52-4828-994F-0837AF9A586C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.JQuery.DataTables", "Mvc.JQuery.DataTables\Mvc.JQuery.DataTables.csproj", "{2583FCEF-E898-458D-9016-2F294B31F65F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mvc.JQuery.Datatables.Templates", "Mvc.JQuery.Datatables.Templates\Mvc.JQuery.Datatables.Templates.csproj", "{8DA3D5E6-D714-40C3-B6CB-E88D852C5175}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mvc.JQuery.Datatables.Templates", "Mvc.JQuery.Datatables.Templates\Mvc.JQuery.Datatables.Templates.csproj", "{8DA3D5E6-D714-40C3-B6CB-E88D852C5175}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CAB6B030-6006-4546-9A32-8F06AC054E1E}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -120,4 +123,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2C227490-FC3E-4FB8-8CC5-01887C32DABE}
EndGlobalSection
EndGlobal
29 changes: 27 additions & 2 deletions Mvc.Jquery.DataTables.Tests/Mvc.JQuery.DataTables.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit.3.13.2\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand All @@ -11,6 +12,8 @@
<AssemblyName>Mvc.JQuery.DataTables.Tests</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -42,8 +45,24 @@
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.6.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll</HintPath>
<Reference Include="nunit.core, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.core.interfaces, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.core.interfaces.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="nunit.util, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\nunit.util.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="NUnit.VisualStudio.TestAdapter, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4cb40d35494691ac, processorArchitecture=MSIL">
<HintPath>..\packages\NUnitTestAdapter.WithFramework.2.0.0\lib\NUnit.VisualStudio.TestAdapter.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
Expand Down Expand Up @@ -106,4 +125,10 @@
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NUnit.3.13.2\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.13.2\build\NUnit.props'))" />
</Target>
</Project>