1.0.8 • Published 10 months ago

odata-tools v1.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

odata-tools

Anything to odata query.

使用示例

AntdProTable

使用方式

import { antdProTableToODataQueryString } from 'odata-tools';
// ProTable的request中使用
 request={async (params, sort, filter) => {
          const msg = await getUserOdata(
            antdProTableToODataQueryString(
              columns,
              params,
              sort,
              filter,
              'expand=roles(select=id,name,key)&orderby=creationTime desc',
            ),
          );
          return {
            data: msg.value,
            success: true,
            total: msg['@odata.count'],
          };
        }}
      />

生成原理

根据column对应的valueType做处理。不存在默认为text。

// 已实现的column valueType处理:
const processingFunctions: Record<string, ProcessingFunction> = {
  text: (key, value) => `contains(${key},'${value}')`,
  select: (key, value) => `${key} eq ${value}`,
  date: (key, value) => `${key} eq ${value}`,
  dateRange: (key, value) => `${key} ge ${value[0]} and ${key} le ${value[1]}`,
};

自定义具体列筛选

优先级大于valueType

// 自定义某个column的查询,例如:
    {
      title: '自定义筛选',
      dataIndex: 'aa',
      search: true,
      valueEnum: {
        AA: { text: 'AAText' },
        BB: { text: 'BBText' },
        CC: { text: 'CCText' },
      },
      odataFilter: (key, value) => `${key} eq '${value}'`,
    },
1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

12 months ago

1.0.0

12 months ago