Browse Source

feat: pagination and filtering

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/636/head
Pranav C 3 years ago
parent
commit
88accf47b6
  1. 3
      packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue
  2. 8
      packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts
  3. 20
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

3
packages/nc-gui/components/project/spreadsheet/components/virtualCell/components/listItems.vue

@ -142,7 +142,8 @@ export default {
limit: this.size,
tn: this.tn,
view_id: this.$route.params.id,
offset: this.size * (this.page - 1)
offset: this.size * (this.page - 1),
query: this.query
}])
} else {
if (!this.api) {

8
packages/nocodb/src/lib/dataMapper/lib/sql/BaseModelSql.ts

@ -914,7 +914,12 @@ class BaseModelSql extends BaseModel {
* @memberof BaseModel
* @throws {Error}
*/
async countByPk({ where = '', conditionGraph = null, having = '' }) {
async countByPk({
where = '',
conditionGraph = null,
having = '',
condition
}) {
try {
if (this.isPg() && !conditionGraph && !where && !having) {
const res = (
@ -935,6 +940,7 @@ class BaseModelSql extends BaseModel {
return await this._run(
this.$db
.conditionGraph(conditionGraph)
.condition(condition, this.selectQuery(''))
.count(`${this.tn}.${(this.pks[0] || this.columns[0]).cn} as count`)
.xwhere(where, { ...this.selectQuery(''), ...this.selectFormulasObj })
.xhaving(having, this.selectQuery(''))

20
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -3455,7 +3455,7 @@ export default class NcMetaMgr {
const tn = args.args?.tn;
// @ts-ignore
const queryParams = JSON.parse(viewMeta.query_params);
// const queryParams = JSON.parse(viewMeta.query_params);
const apiBuilder = this.app?.projectBuilders
?.find(pb => pb.id === viewMeta.project_id)
@ -3468,13 +3468,27 @@ export default class NcMetaMgr {
const model = apiBuilder.xcModels?.[tn];
const primaryCol = apiBuilder?.getMeta(tn)?.columns?.find(c => c.pv)?.cn;
const commonParams =
primaryCol && args.args.query
? {
condition: {
[primaryCol]: {
like: `%${args.args.query}%`
}
}
}
: {};
return {
list: await model?.list({
fields: model.getTablePKandPVFields(),
limit: args.args.limit,
offset: args.args.offset
offset: args.args.offset,
...commonParams
}),
count: (await model?.countByPk({}))?.count
count: (await model?.countByPk(commonParams as any))?.count
};
} catch (e) {
console.log(e);

Loading…
Cancel
Save