Feb 28, 2015, 10:28 PM
[CLOSED] Implement the remote sort gridpanel call
I need to apply the "sort" to the next code, I use it from a gridpanel
generic .ashx handler
Here is the GetPagingFilterHeader function, I need to have the sort code, as it is in this example:
https://examples3.ext.net/#/GridPane...Header/Remote/
pxyUsuario class:
generic .ashx handler
StoreRequestParameters prms2 = new StoreRequestParameters(context);
_iStart = prms2.Start;
_iLimit = prms2.Limit;
_sOrderBy = prms2.Sort[0].Property; //prms.SimpleSort;
_sOrderDirection = prms2.Sort[0].Direction.ToString(); //prms.SimpleSortDirection
_sFilter = context.Request["filterheader"];
context.Response.Write(JSON.Serialize(new UsuarioRepository().GetPagingFilterHeader(_iStart, _iLimit, _sOrderBy, _sOrderDirection, _sFilter)));
break;
Here is the GetPagingFilterHeader function, I need to have the sort code, as it is in this example:
https://examples3.ext.net/#/GridPane...Header/Remote/
public Paging<pxyUsuario> GetPagingFilterHeader(int start, int limit, string sort, string dir, string filter)
{
using (IDbConnection Db = DataConn.GetDbFactory().OpenDbConnection())
{
List<pxyUsuario> pxyUsuarios = Db.Select<pxyUsuario>();
FilterHeaderConditions fhc = new FilterHeaderConditions(filter);
foreach (FilterHeaderCondition condition in fhc.Conditions)
{
string dataIndex = condition.DataIndex;
FilterType type = condition.Type;
string op = condition.Operator;
object value = null;
switch (condition.Type)
{
case FilterType.Boolean:
value = condition.Value<bool>();
break;
case FilterType.Date:
switch (condition.Operator)
{
case "=":
value = condition.Value<DateTime>();
break;
case "compare":
value = FilterHeaderComparator<DateTime>.Parse(condition.JsonValue);
break;
}
break;
case FilterType.Number:
bool isInt = pxyUsuarios.Count > 0 && pxyUsuarios[0].GetType().GetProperty(dataIndex).PropertyType == typeof(int);
switch (condition.Operator)
{
case "=":
if (isInt)
{
value = condition.Value<int>();
}
else
{
value = condition.Value<double>();
}
break;
case "compare":
if (isInt)
{
value = FilterHeaderComparator<int>.Parse(condition.JsonValue);
}
else
{
value = FilterHeaderComparator<double>.Parse(condition.JsonValue);
}
break;
}
break;
case FilterType.String:
value = condition.Value<string>();
break;
default:
throw new ArgumentOutOfRangeException();
}
pxyUsuarios.RemoveAll(item =>
{
object oValue = item.GetType().GetProperty(dataIndex).GetValue(item, null);
string matchValue = null;
string itemValue = null;
if (type == FilterType.String)
{
//matchValue = (string)value;
//itemValue = oValue as string;
matchValue = ((string)value).ToUpper();
itemValue = (oValue as string).ToUpper();
}
switch (op)
{
case "=":
return oValue == null || !oValue.Equals(value);
case "compare":
return !((IEquatable<IComparable>)value).Equals((IComparable)oValue);
case "+":
return itemValue == null || !itemValue.StartsWith(matchValue);
case "-":
return itemValue == null || !itemValue.EndsWith(matchValue);
case "!":
return itemValue == null || itemValue.IndexOf(matchValue) >= 0;
case "*":
return itemValue == null || itemValue.IndexOf(matchValue) < 0;
default:
throw new Exception("Not supported operator");
}
});
}
//-- end filtering ------------------------------------------------------------
//-- start sorting ------------------------------------------------------------
// This is what I need to implement, I copied from the link I mentioned above, obviously the e.Sort doesnt exist in my code
if (e.Sort.Length > 0)
{
pxyUsuarios.Sort(delegate(object x, object y) //here also is not recognized the x and y objects
{
object a;
object b;
int direction = e.Sort[0].Direction == Ext.Net.SortDirection.DESC ? -1 : 1;
a = x.GetType().GetProperty(e.Sort[0].Property).GetValue(x, null);
b = y.GetType().GetProperty(e.Sort[0].Property).GetValue(y, null);
return CaseInsensitiveComparer.Default.Compare(a, b) * direction;
});
}
//-- end sorting ------------------------------------------------------------
//-- start paging ------------------------------------------------------------
if ((start + limit) > pxyUsuarios.Count)
{
limit = pxyUsuarios.Count - start;
}
List<pxyUsuario> rangeUsuario = (start < 0 || limit < 0) ? pxyUsuarios : pxyUsuarios.GetRange(start, limit);
return new Paging<pxyUsuario>(rangeUsuario, pxyUsuarios.Count);
}
pxyUsuario class:
public class pxyUsuario
{
public int Id { get; set; }
public string Cuenta { get; set; }
public string UsuarioPerfil { get; set; }
public string Nombre { get; set; }
public string Email { get; set; }
public string TelCasa { get; set; }
public string TelCelular { get; set; }
public bool DeviceAny { get; set; }
public string DeviceSerial { get; set; }
public DateTime Lastaccess { get; set; }
public bool Estatus { get; set; }
}
Last edited by Daniil; Mar 10, 2015 at 11:34 AM.
Reason: [CLOSED]