NSG.PrimeNG.LazyLoading - PHuhn/NSG.PrimeNG GitHub Wiki

Table of Contents

Assembly: NSG.PrimeNG.LazyLoading

Class: IFilterMetadata

Json of interface: {"value":"S","matchMode":"startsWith","operator":"and"}


Properties

value

value: any string/numeric/etc

matchMode

matchMode: string, with values of: gt/lt/equals/lte/gte/notequals/contains/startswith/endswith

operator

operator: string and/or

Class: FilterMetadata

Json of class: {"value":"S","matchMode":"startsWith","operator":"and"}


Properties

value

value: any string/numeric/etc

matchMode

matchMode: string, with values of: gt/lt/equals/lte/gte/notequals/contains/startswith/endswith

operator

operator: string and/or

Class: LazyLoadEvent

PrimeNG structure, used by lazy loading feature. Class LazyLoadEvent ported from PrimeNG to this library. Generally, populated by the PrimeNG filter feature.

For example: An example of the JSON: {"first":0,"rows":3,"sortOrder":1, "filters":{"ServerId":{"value":1,"matchMode":"eq"}, "Mailed":{"value":"false","matchMode":"eq"}, "Closed":{"value":"false","matchMode":"eq"}, "Special":{"value":"false","matchMode":"eq"}}, "globalFilter":null}


Fields

first

First record #.

rows

  1. of rows to return (page size).

sortField

Sort field.

sortOrder

Ascending or desending sort order. 1 = asc, -1 = desc

multiSortMeta

multiSortMeta, not implemented.

filters

A dictionary of filters. Key of the dictionary is the field name, object is value(s) and match mode.

For example: "filters":{"ServerId":{"value":1,"matchMode":"eq"}, "Mailed":{"value":"false","matchMode":"eq"}, "Closed":{"value":"false","matchMode":"eq"}, "Special":{"value":"false","matchMode":"eq"}},

globalFilter

globalFilter, not implemented.

Methods

ToString()

Returns a string that represents of the current object. This method overrides the default 'to string' method.

Return Value

A formatted string of the object's values.


Class: LazyLoadEvent2

PrimeNG structure, used by lazy loading feature. Class LazyLoadEvent ported from PrimeNG to this library. Generally, populated by the PrimeNG filter feature.

For example: An example of the JSON: {"first":0,"rows":5,"sortOrder":1,"filters":{ "NoteTypeDesc":[ {"value":"F","matchMode":"startsWith","operator":"and"}, {], "NoteTypeShortDesc":[ {"value":"S","matchMode":"startsWith","operator":"and"}] },"globalFilter":null}


Fields

first

First record #.

rows

  1. of rows to return (page size).

sortField

Sort field.

sortOrder

Ascending or desending sort order. 1 = asc, -1 = desc

multiSortMeta

multiSortMeta, not implemented.

filters

A dictionary of filters. Key of the dictionary is the field name, object is value(s) and match mode.

For example: "filters":{"ServerId":{"value":1,"matchMode":"eq"}, "Mailed":{"value":"false","matchMode":"eq"}, "Closed":{"value":"false","matchMode":"eq"}, "Special":{"value":"false","matchMode":"eq"}},

globalFilter

globalFilter, not implemented.

Methods

ToString()

Returns a string that represents of the current object. This method overrides the default 'to string' method.

For example: LazyLoadEvent2:[first:]

Return Value

A formatted string of the object's values.


Namespace: NSG.PrimeNG.LazyLoading

The namespace contains a class used by lazy loading feature and filter features. The lazy loading feature allows one to return a page of data and combined with the filtering and sorting features gives a rich feature of transferring large set of data efficiently.

For example: A full example of the original LazyLoadEvent as follows:

string _jsonString =
    "{\"first\":0,\"rows\":3," +
    "\"sortOrder\":-1,\"sortField\":\"NoteTypeSortOrder\"," +
    "\"filters\":{\"NoteTypeDesc\":{\"value\":\"SO\",\"matchMode\":\"StartsWith\"}}}";
JavaScriptSerializer _js_slzr = new JavaScriptSerializer();
LazyLoadEvent _loadEvent = (LazyLoadEvent)_js_slzr.Deserialize(_jsonString, typeof(LazyLoadEvent));
List<NoteType> _rows = NoteTypes.AsQueryable()
    .LazyOrderBy(_loadEvent)
    .LazyFilters(_loadEvent)
    .LazySkipTake(_loadEvent).ToList();

For example: A full example of the of corrected LazyLoadEvent2 as follows:

string _pagination = "{\"first\":0,\"rows\":3," +
    "\"sortOrder\":-1,\"sortField\":\"NoteTypeSortOrder\"," +
    "{\"filters\":{\"NoteTypeDesc\":[" +
    "{\"value\":\"SO\",\"matchMode\":\"startsWith\",\"operator\":\"or\"}," +
    "{\"value\":\"6\",\"matchMode\":\"contains\",\"operator\":\"or\"}]}}";
LazyLoadEvent2 _loadEvent = JsonConvert.DeserializeObject<LazyLoadEvent2>(_pagination);
List<NoteType> _rows = NoteTypes.AsQueryable()
    .LazyOrderBy2(_loadEvent)
    .LazyFilters2(_loadEvent)
    .LazySkipTake2(_loadEvent).ToList();

Class: Helpers

Set of static helper methods, meant to be used as extension methods.


Methods

LazyOrderBy2<T>(Linq.IQueryable<T>, LazyLoadEvent2)

Sort this IQueryable, with: sortField and sortOrder 1=ascending -1=descending

For example: This sample shows how to call this method, where _incidentQuery is IQueryable of Incident:

JavaScriptSerializer _jsSlzr = new JavaScriptSerializer();
_loadEvent = (LazyLoadEvent) _jsSlzr.Deserialize( jsonString, typeof(LazyLoadEvent) );
_incidentQuery = _incidentQuery.LazyOrderBy( _loadEvent );

Note: 'OrderBy' must be called before the method 'Skip'.

Parameters
T

Some class (database)

qry

IQueryable query of T (above class)

lle

PrimeNG lazy loading event (LazyLoadEvent2) structure

Return Value

IQueryable query of T (with ascending or descending sort applied)


LazySkipTake2<T>(Linq.IQueryable<T>, LazyLoadEvent2)

Skip forward in the database and take n # of rows

For example: This sample shows how to call this method, where _incidentQuery is IQueryable of Incident:

JavaScriptSerializer _jsSlzr = new JavaScriptSerializer();
_loadEvent = (LazyLoadEvent) _jsSlzr.Deserialize( jsonString, typeof(LazyLoadEvent) );
_incidentQuery = _incidentQuery.LazySkipTake( _loadEvent );

Note: 'OrderBy' must be called before the method 'Skip'.

Parameters
T

Some class (database)

qry

IQueryable query of T (above class)

lle

PrimeNG lazy loading event (LazyLoadEvent) structure

Return Value

IQueryable query of T (with skip/take applied)


LazyFilters<T>(Linq.IQueryable<T>, LazyLoadEvent)

Apply filter to an IQueryable from PrimeNG request. Filter: key of the dictionary is the field name, object is value(s) and match mode

For example: This sample shows how to call this method, where _incidentQuery is IQueryable of Incident:

JavaScriptSerializer _jsSlzr = new JavaScriptSerializer();
_loadEvent = (LazyLoadEvent) _jsSlzr.Deserialize( jsonString, typeof(LazyLoadEvent) );
_incidentQuery = _incidentQuery.LazyFilters( _loadEvent );
Parameters
T

Some class (database)

qry

IQueryable query of T (above class)

lle

PrimeNG lazy loading event (LazyLoadEvent) structure

Return Value

IQueryable query of T (with where filters applied)


OrExpression<T>(Linq.Expressions.Expression{System.Func<T>System.Boolean}}, Linq.Expressions.Expression{System.Func<T>System.Boolean}})

Implement an Or conditional

Parameters
T

Some class (database)

left

The left (this) expression

right

The right expression

Return Value

An expression that can be used for querying data sets


AndExpression<T>(Linq.Expressions.Expression{System.Func<T>System.Boolean}}, Linq.Expressions.Expression{System.Func<T>System.Boolean}})

Implement an And conditional

Parameters
T

Some class (database)

left

The left (this) expression

right

The right expression

Return Value

An expression that can be used for querying data sets


LazyDynamicFilterExpression<TEntity>(String, String, String, Type, String)

A method to create an expression dynamically given a generic entity, and a propertyName, operator and value.

  • Operators
  • contains
  • startsWith
  • endsWith
  • equals
  • notEquals
  • lt
  • lte
  • gt
  • gte
Note: The following code mostly come from: https://stackoverflow.com/questions/2497303/how-to-specify-dynamic-field-names-in-a-linq-where-clause

Note: The 'in' operator is not handled and will throw an exception:

System.ArgumentOutOfRangeException

Unhandled or invalid operators

Parameters
TEntity

The class to create the expression for. Most commonly an entity framework entity that is used for a DbSet.

propertyName

A string value of the property name.

match

A string representing an operator (see above list of operators).

value

A string representation of the value.

valueType

The underlying type of the value

op

operator and/or

Return Value

An expression that can be used for querying data sets (Expression>)


AsType(String, Type)

Extract this string value as the passed in object type (convert/cast).

Parameters
value

The value, as a string

type

The desired type

Return Value

The value, as the specified type


Class: ISortMeta

a list sorting item, can be sorted on multiple fields


Properties

field

field: field name to sort

order

order: accending/descending

Class: SortMeta

a list sorting item, can be sorted on multiple fields


Properties

field

field: field name to sort

order

order: accending/descending

⚠️ **GitHub.com Fallback** ⚠️