Skip to content

Commit

Permalink
Added Localizations and Default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mesuttalebi committed Feb 24, 2016
1 parent 8cab577 commit f1be6df
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 35 deletions.
Binary file modified mesoft.gridview/Scripts/_references.js
Binary file not shown.
12 changes: 12 additions & 0 deletions mesoft.gridview/Scripts/locales/megridview.en.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function ($) {
"use strict";

$.fn.meGridView.locales['en'] = {
PageSizeText: "Page Size",
PageText: "Page",
PreviousPage: "Previous Page",
NextPage: "Next Page"
};

$.extend($.fn.meGridView.defaults, $.fn.meGridView.locales['en']);
})(jQuery);
12 changes: 12 additions & 0 deletions mesoft.gridview/Scripts/locales/megridview.tr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function ($) {
"use strict";

$.fn.meGridView.locales['tr'] = {
PageSizeText: "Sayfa Büyüklüğü",
PageText: "Sayfa",
PreviousPage: "Önceki Sayfa",
NextPage: "Sonraki Sayfa"
};

$.extend($.fn.meGridView.defaults, $.fn.meGridView.locales['tr']);
})(jQuery);
75 changes: 43 additions & 32 deletions mesoft.gridview/Scripts/megridview.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
/*
megridview v0.3.1
megridview v0.3.2
Developed By Mesut Talebi ([email protected])
Open Source And no licence :) free to use
*/
(function ($) {
$.fn.meGridView = function () {
(function ($) {
$.fn.meGridView = function (options) {

var $gridviewObject = new Object();

var options = {
ShowPageOptions : true,
ItemsPerPage : 10,
PageOptions: [10, 20, 50, 100],
PageSizeText: "Page Size",
PageText: "Page"
}

var defaults = $.extend({}, $.fn.meGridView.defaults, options);

//A function to Automatically insert page options
var writePagerHtml = function (obj) {
var pagerHtml =
'<!-- Pager Left-->' +
'<div class="col-sm-6 col-xs-12">' +
'<!-- Page Size Area -->' +
'<div class="gridview-itemization">';
if (options.ShowPageOptions === true) {
pagerHtml += '<span>Page Size</span>' +
if (defaults.ShowPageOptions === true) {
pagerHtml += '<span> ' + defaults.PageSizeText + ' </span>' +
'<div class="btn-group selectlist dropup" data-resize="auto">' +
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">' +
'<span class="selected-label">' + options.ItemsPerPage + '</span>' +
'<span class="selected-label"> ' + defaults.ItemsPerPage + ' </span>' +
'<span class="caret"></span>' +
'<span class="sr-only">' + options.PageSizeText + '&nbsp;</span>' +
'<span class="sr-only"> ' + defaults.PageSizeText + '&nbsp;</span>' +
'</button>' +
'<ul class="dropdown-menu" role="menu">';
for (var i = 0; i < options.PageOptions.length ; i++) {
pagerHtml += '<li data-value="' + options.PageOptions[i] + '"><a href="#">' + options.PageOptions[i] + '</a></li>';
for (var i = 0; i < defaults.PageOptions.length ; i++) {
pagerHtml += '<li data-value="' + defaults.PageOptions[i] + '"><a href="#">' + defaults.PageOptions[i] + '</a></li>';
}
pagerHtml += '</ul>' +
'<input class="hidden hidden-field" name="itemsPerPage" readonly="readonly" aria-hidden="true" type="text">' +
'</div>';
}
pagerHtml += '<span>' +
'<span class="gridview-start">1</span> - <span class="gridview-end">' + options.ItemsPerPage + '</span>' +
pagerHtml += '<span> ' +
'<span class="gridview-start">1</span> - <span class="gridview-end">' + defaults.ItemsPerPage + '</span>' +
'(<span class="gridview-count">0</span>)' +
'</span>' +
'</div>' +
Expand All @@ -54,11 +48,11 @@
'<span class="fa fa-chevron-left"></span>' +
'<span class="sr-only">Previous Page</span>' +
'</button>' +
'<label class="page-label" id="myPageLabel">&nbsp;' + options.PageText + '&nbsp;</label>' +
'<label class="page-label" id="myPageLabel">&nbsp;' + defaults.PageText + '&nbsp;</label>' +
'<input type="number" class="form-control gridview-secondaryPaging active" aria-labelledby="myPageLabel" value="1">' +
'<span>' +
'/ <span class="gridview-pages">0</span>' +
'</span>' +
' / <span class="gridview-pages">0</span>' +
'</span>&nbsp;' +
'<button type="button" class="btn btn-default btn-sm gridview-next">' +
'<span class="fa fa-chevron-right"></span>' +
'<span class="sr-only">Next Page</span>' +
Expand All @@ -76,7 +70,7 @@

//The gridview object that we are working on it
var gridview = this;

//Inserts Pager Html
writePagerHtml(gridview);

Expand All @@ -85,7 +79,7 @@
LoadFirstPage(gridview);

//Btn gridview-next click event
$(gridview).on('click', 'button.gridview-next', function () {
$(gridview).on('click', 'button.gridview-next', function () {
if ($('button.gridview-next', gridview).is(':enabled')) {
NextPage(gridview);
}
Expand All @@ -107,7 +101,7 @@
var size = $($li).data('value');
var pageSize = $gridviewObject.ItemsPerPage;
if (size != pageSize)
ChangePageSize(size, gridview);
ChangePageSize(size, gridview);
});

//Pressing Enter event for page number input
Expand All @@ -130,7 +124,7 @@
});

//Searching data
$(gridview).on('click', '.search button', function() {
$(gridview).on('click', '.search button', function () {
var $searchTerm = $('.search input[type=search]', gridview).val();

if ($searchTerm.length >= 0) {
Expand Down Expand Up @@ -179,7 +173,7 @@
var obj = $('.active', p)[0].nodeName.toLowerCase();

$(obj + '.active', p).removeClass('active');
$(this).parents(obj).addClass('active');
$(this).parents(obj).addClass('active');
});
});

Expand Down Expand Up @@ -221,7 +215,7 @@
LoadData(gridview);
}
}

function Init(obj) {
//add icon place holder for sortable fields
$('th.sortable', obj).append('<span class="pull-right fa"></span>');
Expand All @@ -241,15 +235,15 @@
}

function LoadData(obj) {

var data = {
"CurrentPage": $gridviewObject.CurrentPage,
"ItemsPerPage": $gridviewObject.ItemsPerPage,
"SearchTerm": $gridviewObject.SearchTerm,
"Sort": $gridviewObject.Sort,
"Filters": $gridviewObject.Filters
};

GetData(data, obj);
}

Expand Down Expand Up @@ -406,6 +400,23 @@
$gridviewObject.CurrentPage = 1;
$gridviewObject.ItemsPerPage = $gridviewObject.PageOptions[0];
LoadData(obj);
}
};
}
};

$.fn.meGridView.defaults = {
ShowPageOptions: true,
ItemsPerPage: 10,
PageOptions: [10, 20, 50, 100]
};

$.fn.meGridView.locales = [];

$.fn.meGridView.locales['en'] = {
PageSizeText: "Page Size",
PageText: "Page",
PreviousPage: "Previous Page",
NextPage: "Next Page"
};

$.extend($.fn.meGridView.defaults, $.fn.meGridView.locales['en']);
}(jQuery));
12 changes: 9 additions & 3 deletions mesoft.gridview/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@{
@using System.Threading
@{
ViewBag.Title = "Home Page";
}

<div class="jumbotron">
<h1>MeSoft Gridview V0.3.1</h1>
<h1>MeSoft Gridview V0.3.2</h1>
<p class="lead">No Magic! Simple To Use, Simple to Develop</p>
<p><a href="#" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>
Expand All @@ -14,7 +15,12 @@
</div>

@section Scripts {
<script>

@{
string culture = Thread.CurrentThread.CurrentCulture.Name;
}
<script src=@(Url.Content(string.Format("~/Scripts/locales/megridview.{0}.js", culture.Substring(0, culture.IndexOf("-") == 0 ? culture.Length : culture.IndexOf("-")))))></script>
<script>
$('.gridview1').meGridView();
//$('.gridview2').meGridView();
</script>
Expand Down
2 changes: 2 additions & 0 deletions mesoft.gridview/mesoft.gridview.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@
<Content Include="Scripts\jquery.validate.min.js" />
<Content Include="Scripts\jquery.validate.unobtrusive.js" />
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
<Content Include="Scripts\locales\megridview.en.js" />
<Content Include="Scripts\locales\megridview.tr.js" />
<Content Include="Scripts\megridview.js" />
<Content Include="Scripts\modernizr-2.8.3.js" />
<Content Include="Scripts\npm.js" />
Expand Down

0 comments on commit f1be6df

Please sign in to comment.