Search This Blog

Create Custom QuickFilter which selects distinct values of same table/view columns

We created a file MyTableClassLookup.cs for custom lookup. And change some fields name according to your requirement.
using ERP.MyModule.Entities;
using Serenity.ComponentModel;
using Serenity.Data;
using Serenity.Web;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
namespace ERP.MyModule
{
[LookupScript("MyModule.CustomLookup", Expiration = -1, Permission = "*")]
public class MyTableClassLookup : RowLookupScript<MyTableClassRow>
{
public MyTableClassLookup()
{
IdField = TextField = "Unit"; //where Unit is property in MyTableClassRow class
}

protected override void PrepareQuery(SqlQuery query)
{
var fld = MyTableClassRow.Fields;


query
.Distinct(true)
.Select(fld.Unit)
.Where(fld.Unit.IsNotNull());

}

protected override void ApplyOrder(SqlQuery query)
{
}

}
}
We add the attribue [LookupEditor(typeof(MyTableClassLookup))] in MyTableClassRow class for property unit.

No comments:

Post a Comment

Web Statistics