Как добавить фильтры данных таблицы в личном кабинете

Как реализовать

Указываем у колонок параметр "В фильтре"

Обрабатываем в GetItems. Извлекаем из @filters по коду и применяем фильтры для извлечения нужных записей.  

CREATE PROCEDURE [dbo].[crud_watch_filters_getItems]
	@filters CRUDFilterParameter READONLY,  
	@sort sql_variant,
	@direction nvarchar(8),
	@page int,
	@pageSize int,
	@username nvarchar(32)
AS
BEGIN
	declare   @ids TABLE (id int)

	-- filters...
	declare @filterCustomer nvarchar(128), @filterStatus nvarchar(64), @filterCreated nvarchar(64),
    		@filterPrice nvarchar(64), @filterisVisible bit, @filterCreated1 nvarchar(128), @filterStatus1 int
	select @filterCustomer = Value from @filters where [Key] = 'customer'
    select @filterStatus = Value from @filters where [Key] = 'status'
	select @filterCreated = Value from @filters where [Key] = 'created'
    select @filterPrice = Value from @filters where [Key] = 'price'
    select @filterisVisible = try_cast(Value as bit) from @filters where [Key] = 'isVisible'
	select @filterCreated1 = Value from @filters where [Key] = 'created1'
    select @filterStatus1 = try_cast(Value as int) from @filters where [Key] = 'status1'

    
    declare @dateStart date, @dateEnd date
    set @dateStart = try_convert(date, dbo.str_splitPart(@filterCreated,' - ',1), 104)
    set @dateEnd = try_convert(date, dbo.str_splitPart(@filterCreated,' - ',2), 104)
    
    declare @priceBegin int, @priceEnd int
    select @priceBegin = (select top 1 value from dbo.split(@filterPrice, ','))
    select @priceEnd = (select top 1 value from dbo.split(@filterPrice, ',')
    order by value desc)
    
	insert into @ids
	select o.id
	from tst_orders o
    join tst_products p on p.id = o.productID
    join tst_customers c on c.id = o.customerID
    where	(isnull(@filterCustomer, '') = '' or c.name like '%'+@filterCustomer+'%' or c.fio like '%'+@filterCustomer+'%')
    and		(isnull(@filterStatus, '') = '' or statusID in (select try_cast(Value as int) from dbo.split(@filterStatus, ',')))
    and 	(isnull(@filterCreated,'') = '' or convert(date, o.created, 104) between @dateStart and @dateEnd)
    and		(isnull(@filterCreated1, '') = '') or convert(date, o.created, 104) = convert(date, @filterCreated1, 104)
    and		(isnull(@filterisVisible,0) = 0 or isVisible = 1)
    and		(isnull(@filterStatus1,0) = 0 or statusID = @filterStatus1)
  --- and		(isnull(@filterPrice, '') = '' or o.price between @priceBegin and @priceEnd)
	-- SELECT 1
	Select 
    	o.id id,
        c.name customer,
        c.fio desc_customer,
        p.name,
        (select name from tst_statuses where id = o.statusID) status,
        isnull(format(o.created, 'dd.MM.yyyy'), '01.01.1900') created,
        isnull(o.price, 0)price,
        isnull(isVisible, 0)isVisible
    from tst_orders o
    join tst_products p on p.id = o.productID
    join tst_customers c on c.id = o.customerID
	where	o.id in (select id from @ids)
	order by  
		case when @sort = 'p.name' and @direction = 'down' then c.name end desc,
		case when @sort = 'p.name' and @direction = 'up' then c.name end asc,
        case when @sort = 'created' and @direction = 'down' then o.created end desc,
		case when @sort = 'created' and @direction = 'up' then o.created end asc,
        case when @sort = 'price' and @direction = 'down' then o.price end desc,
		case when @sort = 'price' and @direction = 'up' then o.price end asc
	OFFSET @PageSize * (@Page - 1) ROWS
	FETCH NEXT @PageSize ROWS ONLY;
	
	-- SELECT 2
	select count(*) from @ids	

	--select 3

	-- 4 SELECT Footer data or kanban/gantt data
END

 

Насколько полезна эта возможность?

Другие модули

Последние обновления

Платформа Falcon Space

Это снижение стоимости владения

за счет меньшего количества людей для поддержки

Это быстрое внесение изменений

по ходу эксплуатации программы

Это современный интерфейс

полная адаптация под мобильные устройства

Сайт использует Cookie. Правила конфиденциальности OK