I have a table displaying search results with server side Pagination but when I click the columns, there is no sorting taking place and the server displays the results again for any of the column arrow clicks. Is there any way I can limit the pagination to take place only for the page arrows in the footer and then sorting to take place for the displayed results when i click the columns?
<q-table
dense
:title="Patient result"
:data="searchResultList"
:columns="columns"
:pagination="serverPagination"
row-key="name"
:no-data-label="noDataMessage"
:loading="loading"
#request="request"
>
data() {
return {
filter: '',
columns: [
{
name: 'patientId',
required: true,
label: 'patientId',
align: 'left',
field: row => row.patientId,
format: val => `${val}`,
sortable: true,
}
{
name: 'lastname', align: 'center', label: 'lastname', field: 'lastname', sortable: true,
},
{
name: 'firstname', align: 'center', label: 'firstname', field: 'firstname', sortable: true,
},
{
name: 'dob', align: 'center', label: 'dob', field: 'dob', sortable: true,
},
],
page: 1,
rowsInPage: 25,
};
computed: {
serverPagination() {
return {
sortBy: this.paginationObject.sortBy,
descending: this.paginationObject.descending,
page: this.paginationObject.page,
rowsNumber: this.patientSearchResults.count,
rowsPerPage: this.paginationObject.rowsPerPage,
};
paginationObject: {
sortBy: 'name',
descending: false,
page: 1,
rowsPerPage: 25,
methods: {
request(props) {
this.$store.dispatch('patientSearch/setPaginationObject', props);
},
Use sort-method. You can write a custom function where you can pass the rows(Not all but according to pagination i.e. if the selected page is 1 the rows will be 0-5 from your array. Here I'm guessing the default visible rows will be 5.)
Check out this API reference - https://quasar.dev/vue-components/table
In QTable API, you will find the details about this method.
Related
I use vue-good-table object to render table in Vue.js. I use paging and sorting serverside.
My code:
<vue-good-table v-if="authorizations"
id="AuthorizationsTable"
ref="refToAuthorizationsTable"
#on-page-change="onPageChange"
#on-sort-change="onSortChange"
#on-column-filter="onColumnFilter"
#on-per-page-change="onPerPageChange"
mode="remote"
:columns="columns"
:rows="authorizations"
:totalRows="totalRecords"
:pagination-options="{
enabled: true,
mode: 'pages',
nextLabel: 'następna',
prevLabel: 'poprzednia',
ofLabel: 'z',
pageLabel: 'strona',
rowsPerPageLabel: 'wierszy na stronie',
allLabel: 'wszystko',
dropdownAllowAll: false
}"
:sort-options="{
enabled: true,
initialSortBy: {
field: 'id',
type: 'asc'
}
}">
(...)
export default {
name: 'AuthoritiesAdministration',
components: {},
data() {
return {
totalRecords: 0,
serverParams: {
columnFilters: {},
sort: {
field: 'id',
type: 'asc'
},
page: 1,
perPage: 10
},
rows: [],
columns: [
{
label: 'ID',
field: 'id',
type: 'number',
tdClass: 'vue-good-table-col-100'
},
{
label: 'Data wystawienia',
field: 'issueDate',
formatFn: this.formatDate,
tdClass: 'vue-good-table-col-200',
},
{
label: 'Nazwa operatora',
field: 'operator',
sortable: true,
formatFn: this.formatOperatorName,
},
{
label: 'Login',
field: 'operator.login'
},
{
label: 'Spółka',
field: 'company.description',
type: 'text',
},
{
label: 'Data ważności',
field: 'endDate',
type: 'text',
formatFn: this.formatDate,
},
{
label: 'Akcje',
field: 'btn',
tdClass: 'vue-good-table-col-250',
sortable: false
}
],
}
},
(...)
methods: {
updateParams(newProps) {
this.serverParams = Object.assign({}, this.serverParams, newProps);
},
onPageChange(params) {
this.updateParams({page: params.currentPage});
this.loadAuthorizations();
},
onPerPageChange(params) {
this.updateParams({
perPage: params.currentPerPage
});
this.loadAuthorizations();
},
onSortChange(params) {
this.updateParams({
sort: {
type: params[0].type,
field: params[0].field
}
});
this.loadAuthorizations();
},
onColumnFilter(params) {
this.updateParams(params);
this.loadAuthorizations();
},
loadAuthorizations() {
getAllAuthorizationsLightWithPagination(this.$store.getters.loggedUser.token, this.serverParams).then(response => {
this.totalRecords = response.data.totalRecords;
this.rows = response.data.authorizations;
}).catch(err => {
this.$showError(err, true);
});
},
I have noticed that there are sent 3 requests to the server instead of 1: there are called methods like onPageChange, onPerPageChange and onSortChange but only the first time when my page is loaded. It is unnecessary. I have one method in "mounted" section where I load the first 10 results (sorting and paging by default). It's common, well-known problem with vue-good-table? Or maybe should I add an additional flag to not to invoke these 3 methods unnecessarily when the page is loaded?
Your onSortChange method is called at the table loading because you made a initialSortBy with specific values. To remove this calling juste remove
initialSortBy: {
field: 'id',
type: 'asc'
}
from you table configuration, but your sort will not be set, so I think this should be a legit function call.
The onPerPageChange and onPageChange are triggered by the config below
:pagination-options="{
enabled: true,
...
}
just remove the colon before pagination-options to have a config like this
pagination-options="{
enabled: true,
...
}
Filtering of jqgrid client side. The Problems iam facing are:
Filtering is working only in two columns(Project Ref and Project name in the below code) and only or some part of the word.
Filtering is not working for the data which is coming another table. I am using two datatables for retrieving of data. Works only for the direct table doesnt work for referenced table data.
Can I have theesearch without Loadonce true.Because it is not allowing to reload
I have tried with the following below code let me know where iam doing wrong
In view:
$(document).ready(function () {
$("a.button").button();
var url = '#Url.Action("ListAllProjects")' + '?s_partId=' + '#ViewBag.PartId';
var colNames = ['<input type="checkbox" onclick="CheckAll(this.checked,\'chkOF_\',event);" name="checkall">',
'Status',
'Project Ref',
'Project Name',
'Customer',
'CreatedBy',
'Creation Date',
'Last Modified',
'LastModifiedDate',
'Edit'];
var colModel = [
{ name: 'ProjectId', index: 'ProjectId', align: 'left', formatter: checkFormatter, width: 20, search: true },
{ name: 'ProjectStatusId', index: 'ProjectStatusId', edittype: 'image', align: 'left', width: 70, formatter: imageFormatter, search: true },
{ name: 'ProjectReference', index: 'ProjectReference', align: 'left', width: 100, formatter: 'showlink', formatoptions: { "baseLinkUrl": "/Ordernew/Home" }, search: true },
{ name: 'ProjectName', index: 'ProjectName', align: 'left', width: 150, formatter: 'showlink', formatoptions: { "baseLinkUrl": "/Ordernew/Home" }, search: true },
{ name: 'CustomerName', index: 'CustomerName', align: 'left', width: 150, search: true },
{ name: 'CreatedBy', index: 'CreatedBy', align: 'left', width: 150, search: true },
{ name: 'CreationDate', index: 'CreationDate', align: 'left', width: 100, formatter: 'date', formatoptions: { srcformat: 'ISO8601Long', newformat: 'd-M-y h:m A' }, search: true },
{ name: 'LastModifiedBy', index: 'LastModifiedBy', align: 'left', width: 100, search: true },
{ name: 'LastModifiedDate', index: 'LastModifiedDate', align: 'left', width: 100, formatter: 'date', formatoptions: { srcformat: 'ISO8601Long', newformat: 'd-M-y h:m A' }, search: true },
{ name: 'StatusId', index: 'ProjectStatusId', formatter: myCustomFormatter, align: 'left', width: 70, search: true },
];
var sortname = 'ProjectStatusId';
var sortorder = 'desc';
SetGrid('#jqgprojectnew', '', url, colNames, colModel, sortname, sortorder, -1,'#count',true);
$("#jqgprojectnew").jqGrid('filterToolbar',
{
stringResult: true,
searchOnEnter: false,
defaultSearch: "cn"
});
});
And setting the grid like this which is common for all the grids. But i need search only for the above grid:
function SetGrid(v_gridCtrl,v_pagingCtrl, v_url, v_colNames, v_colModel, v_sortname, v_sortorder, v_Pagesize,Count,Loadonce) {
if (v_Pagesize == undefined)
v_Pagesize = 100;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
url: v_url,
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: v_colNames,
//columns model
colModel: v_colModel,
//pager for grid
pager: $(v_pagingCtrl),
//enable dynamic scrolling
//scroll: true,
//enable npage request parameter
prmNames: { npage: 'npage' },
//number of rows per page
rowNum: v_Pagesize,
rowList: [10, 30, 60, 90, 100, 150, -1],
loadComplete: function () {
$("option[value=-1]").text('All');
$(Count).html($(v_gridCtrl).getGridParam("reccount"));
},
loadonce:Loadonce,
//initial sorting column
sortname: v_sortname,
//initial sorting direction
sortorder: v_sortorder,
//we want to display total records count
viewrecords: true,
//grid height
height: 400,//'100%',
//width: '100%',
scrollOffset: 0,
shrinkToFit: true,
});
}
Code for Adding record :
public bool AddUpdateOrderField(ProjectViewModelNew obj)
{
var rec = new Project
{
ProjectID = Guid.NewGuid(),
ProjectDetail = obj.ProjectDetail,
CustomerId =obj.Id,
ProjectName = obj.ProjectName,
CreatedBy = new UserManager().Userid(),
CreationDate = DateTime.Now,
LastModifiedBy = new UserManager().Userid(),
ProjectRef = obj.ProjectRef,
ProjectStatusId = obj.ProjectStatusId,
LastModifiedDate = DateTime.Now,
OwnerID = new Guid("BEBB9E61-1F06-4762-80D8-5E4D554EAEB5")
};
_context.Projects.AddObject(rec);
_context.SaveChanges();
return true;
}
If you are using local search, you should set loadonce =true and it doesn't matter, from how many tables your data is fetched to the jqgrid. If you want to make loadonce=false, then you should post search criteria to server and perform a database search.
And try removing stringResult: true, to solve your first issue
To make the search case insensitive, add this to jqgrid properties:
ie ;
$(v_gridCtrl).jqGrid({
//url from wich data should be requested
autowidth: true,
.....
ignoreCase:true,
...}
And to reload the grid, try the following code:
$( v_gridCtrl ).trigger( 'reloadGrid', [{ page: 1}] );
I have treegrid extjs 4.. I use proxy read, create, update and delete
but the problem is the treegrid always send update when I click collapse and expand in treegrid..
when I delete update proxy, I got collapsing failed..
anybody have idea to disable updating while collapsing and expanding??
this is my short code
Ext.define('storeLapObjTP', {
extend: 'Ext.data.TreeStore',
//storePlanningTP = Ext.create('Ext.data.TreeStore', {
pageSize:50,
autoSync: true,
model: 'mod_planningTP',
method: 'POST',
proxy: {
type: 'ajax',
api: {
read: base_url+'project/getcomplete',
create: base_url+'project/edit/'+'create',
update: base_url+'project/edit/'+'update',
destroy: base_url+'project/edit/'+'delete'
},
reader: {
type: 'json',
}
},
sorters: [{
property: 'id',
direction: 'desc'
}],
});
Ext.define('gridTPcl', {
extend: 'Ext.tree.Panel',
id:'gridLapTP',
store: storeLapTP = new storeLapObjTP,
collapsible: false,
loadMask: true,
region: 'center',
margins: '0 0 0 0',
autoScroll: false,
useArrows: true,
rootVisible: true,
multiSelect: false,
singleExpand: false,
columns:
[
{
menuDisabled: true,
sortable: false,
xtype: 'actioncolumn',
width: 20,
items: [
{
xtype: 'treecolumn',
header: 'Project Name',
dataIndex: 'name',
width: 300,
align: 'left',
},
{
header: 'Id',
dataIndex: 'id',
hidden:true
},{
text:'Anggaran (Rp.000)',
columns : [
{
header: 'Budget',
dataIndex: 'budget',
width:80,
align: 'center',
}, {
header: 'Total',
dataIndex: 'total',
width:80,
align: 'center',
}
]
}],
selModel: {
selType: 'rowmodel'
},
title: 'Project Tree',
frame: false,
tbar: new Ext.Toolbar({
id: 'tbarlaptp',
items: [
comboYearLapTP,'-',comboYearLapTP,'-',{
id : 'reloadbuttonlaptp',
text: 'Reload',
iconCls: 'reloadButton',
disabled: true,
tooltip: 'Reload Data and Ignore Change',
handler : function(){
this.up().up().store.load();
}
}]
})
,
plugins: [],
});
I did the following code to list the searched items in the grid.
Ext.onReady(function(){
var rowEditing = Ext.create('Ext.grid.plugin.RowEditing');
var searchUsers = new Ext.FormPanel({
renderTo: "searchUsers",
frame: true,
title: 'Search Users',
bodyStyle: 'padding:5px',
width: 500,
items:[{
xtype:'textfield',
fieldLabel: 'Username',
name: 'userName'
}],
buttons:[
{
text:'Search',
formBind: true,
listeners: {
click: function(){
Ext.Ajax.request({
method:'GET',
url : url+'/lochweb/loch/users/getUser',
params : searchUsers.getForm().getValues(),
success : function(response){
console.log(response); //<--- the server response
Ext.define('userList', {
extend: 'Ext.data.Model',
fields: [{ name: 'id', mapping: 'id' },
{ name: 'name', mapping: 'name' },
{ name: 'firstName' ,mapping:'personalInfo.firstName'},
{ name: 'lastName' ,mapping:'personalInfo.lastName'}
]
});
var store = Ext.create('Ext.data.Store', {
model: 'userList',
autoLoad: true,
proxy: {
type: 'ajax',
url : url+'/lochweb/loch/users/getUser',
reader: {
type: 'json',
root: 'Users'
}
}
});
var grid = Ext.create('Ext.grid.Panel', {
renderTo: "searchUsers",
plugins: [rowEditing],
width: 900,
height: 300,
frame: true,
title: 'Users',
store: store,
iconCls: 'icon-user',
columns: [{
text: 'ID',
width: 40,
sortable: true,
dataIndex: 'id'
},
{
text: 'Name',
flex: 1,
sortable: true,
dataIndex: 'name',
field: {
xtype: 'textfield'
}
},
{
text: 'FirstName',
flex: 1,
sortable: true,
dataIndex: 'firstName',
field: {
xtype: 'textfield'
}
},
{
text: 'LastName',
flex: 1,
sortable: true,
dataIndex: 'lastName',
field: {
xtype: 'textfield'
}
}]
});
}
});
}
}
}
]
});
var win = new Ext.Window({
layout:'fit',
closable: false,
resizable: true,
plain: true,
border: false,
items: [searchUsers]
});
win.show();
});
How to Fit the grid inside the Search User window
Add an icon in the grid,so that by clicking on that icon the values from the
grid must be populated to entry form for update.
Here with your code, I've found something:
Use renderTo: "searchUsers" for both FormPanel and the Grid: You add the FormPanel to the window, so this config should not exist (Please refer to renderTo document). So remove them.
Use frame: true for both FormPanel and the Grid: There you have the window as container, so the Form and Grid have been framed inside. So remove them.
You dynamically add the Grid on searching: I recommend you create the result Grid as a separate component (not inside success's result) and specify both Form and Grid as items' components of window. You still can config the Grid with hidden. When Ajax is successful, you can fill the Grid with data returned and show it.
"add an icon in the grid": You can specify a new column in columns of the Grid and use renderer config of grid panel to show the button. For example:
renderer: function(v) {
return "<input type='button'.../>";
}
Finally, you can catch the itemclick event of the grid to know if the column of the clicked cell is the cell which contains the button, the entry will be populated to somewhere you want. Don't forget to specify the grid's Selection model as cellmodel
I have a store on extjs4 that return a list of objects, and i want to set the reader property to be able to count the elements so i can use paging afterward.
For reference, the example that extjs use already comes with a count property(totalCount) and the type of object listed(topics), while mine dont have it, just the list.
for reference:
example
Also, in my code the grid doesnt recognize the limit of results per page, but the paging toolbar does:
var sm = Ext.create('Ext.selection.CheckboxModel');
Ext.define('Cliente', {
extend: 'Ext.data.Model',
fields: [{
name: 'ID',
type: 'int'
}, {
name: 'Nome',
type: 'string'
}, {
name: 'Email',
type: 'string'
}, {
name: 'RazaoSocial',
type: 'string'
}, {
name: 'TipoDeCliente',
type: 'string'
}],
idProperty: 'ID'
});
var store = Ext.create('Ext.data.Store', {
pageSize: 3,
model: 'Cliente',
remoteSort: true,
proxy: {
type: 'ajax',
url: 'http://localhost:4904/Cliente/ObterClientes',
extraParams: {
nome: '',
tipopessoa: '',
email: '',
cpf: '',
estado: '',
cidade: '',
cep: ''
},
reader: {
type: 'json',
root: 'data'
},
simpleSortMode: true
},
sorters: [{
property: 'Email',
direction: 'DESC'
}]
});
var pluginExpanded = true;
var grid = Ext.create('Ext.grid.Panel', {
width: 500,
height: 250,
title: 'Array Grid',
store: store,
selModel: sm,
loadMask: true,
viewConfig: {
id: 'gv',
trackOver: false,
stripeRows: false
},
columns: [{
id: 'gridid',
text: "ID",
dataIndex: 'ID',
hidden: true
}, {
text: 'Nome',
width: 150,
sortable: true,
dataIndex: 'Nome'
}, {
text: 'Tipo de Cliente',
width: 100,
sortable: true,
dataIndex: 'TipoDeCliente'
}, {
text: 'Email',
width: 150,
sortable: true,
dataIndex: 'Email'
}],
bbar: Ext.create('Ext.PagingToolbar', {
store: store,
displayInfo: true,
displayMsg: 'Exibindo clientes {0} - {1} of {2}',
emptyMsg: "Nenhum cliente"
}),
renderTo: 'clientes',
});
store.loadPage(1);
The store needs the total count to calculate the paging parameters and to show the total. Your server side implementation must change to add that count with your data.
Also load the data like this store.load(); instead of loadPage.
EDIT: you also have an extra comma here: renderTo: 'clientes', I would suggest running your code through JSLint.