Skip to content

Commit

Permalink
solve filter bug release 0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mesuttalebi committed May 21, 2015
1 parent 3e7b50f commit 67852a3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion mesoft.gridview/Content/megridview.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
megridview v0.1
megridview v0.3.1
Developed By Mesut Talebi ([email protected])
Open Source And no licence :) free to use
*/
Expand Down
10 changes: 8 additions & 2 deletions mesoft.gridview/Models/GridviewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
using System;
/*
megridview v0.3.1
Developed By Mesut Talebi ([email protected])
Open Source And no licence :) free to use
*/


using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace mesoft.gridview.Models
{
Expand Down
6 changes: 6 additions & 0 deletions mesoft.gridview/Models/MyDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace mesoft.gridview.Models
{
public class MyDbContext : DbContext
{
public MyDbContext()
: base("DefaultConnection")
{

}

public DbSet<Customer> Customers { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
Expand Down
83 changes: 44 additions & 39 deletions mesoft.gridview/Scripts/megridview.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
megridview v0.2
megridview v0.3.1
Developed By Mesut Talebi ([email protected])
Open Source And no licence :) free to use
*/
Expand Down Expand Up @@ -102,53 +102,58 @@
});

//Filtering Data
$(gridview).on('click', 'a.filter', function (ev) {
$(gridview).on('click', '.filter', function (ev) {
ev.preventDefault();

$('li.active').removeClass('active');
$(this).parents('li').addClass('active');

//Collecting new filter values
var $column = $(this).data('filter-column');
var $value = $(this).data('filter-value');
var $operator = $(this).data('filter-operator');
var $conjunction = $(this).data('filter-conjunction');

//creating new filter object
var filterObj = { Column: $column, Value: $value, Operator: $operator, Conjunction: $conjunction };

//Getting existing filters
var filters = $gridviewObject.Filters;

if (filters !== undefined && filters !== null) {
//Searching for same column filters
var foundFlag = false;
for (var i = 0; i < filters.length; i++) {
if (filterObj.Column === filters[i].Column) {
filters[i] = filterObj;
foundFlag = true;
break;
}
}

//same column not found,
//add new column filter to filters
if (!foundFlag) {
$gridviewObject.Filters.push(filterObj);
}
FilterData(this, gridview);

LoadData(gridview);
var p = $(this).parents('.filter-parent');
var obj = $('.active', p)[0].nodeName.toLowerCase();

} else {
$gridviewObject.Filters = [];
$gridviewObject.Filters.push(filterObj);
LoadData(gridview);
}
$(obj + '.active', p).removeClass('active');
$(this).parents(obj).addClass('active');
});
});

function FilterData(object, gridview) {
//Collecting new filter values
var $column = $(object).data('filter-column');
var $value = $(object).data('filter-value');
var $operator = $(object).data('filter-operator');
var $conjunction = $(object).data('filter-conjunction');

//creating new filter object
var filterObj = { Column: $column, Value: $value, Operator: $operator, Conjunction: $conjunction };

//Getting existing filters
var filters = $gridviewObject.Filters;

if (filters !== undefined && filters !== null) {
//Searching for same column filters
var foundFlag = false;
for (var i = 0; i < filters.length; i++) {
if (filterObj.Column === filters[i].Column) {
filters[i] = filterObj;
foundFlag = true;
break;
}
}

//same column not found,
//add new column filter to filters
if (!foundFlag) {
$gridviewObject.Filters.push(filterObj);
}

LoadData(gridview);

} else {
$gridviewObject.Filters = [];
$gridviewObject.Filters.push(filterObj);
LoadData(gridview);
}
}

function Init(obj) {
//add icon place holder for sortable fields
$('th.sortable', obj).append('<span class="pull-right fa"></span>');
Expand Down
2 changes: 1 addition & 1 deletion mesoft.gridview/Views/Home/_GridViewPartial.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">
Select City <span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu">
<ul class="dropdown-menu filter-parent" role="menu">
@foreach (var city in cityFilters)
{
<li><a href="#" class="filter"
Expand Down

0 comments on commit 67852a3

Please sign in to comment.