vue2-datatable-component ajax operations - vuejs2

I am fairly new to Vue JS but have been using JavaScript for quite a while now. I have the vue2-datatable-component by onewaytech installed and have been using the Advanced Example that they have posted. The table is working correctly but am trying to have the buttons in the operations column execute an ajax call to delete the object displayed in that row. I didn't see anything in the documentation about passing the unique ID to the td-Opt so I am stuck.

You will have to use a dynamic component to make it. for example:
data () {
return {
props: ['row'],
supportBackup: true,
supportNested: true,
tblClass: 'table-bordered',
tblStyle: 'color: #666',
pageSizeOptions: [5, 10, 15, 20],
columns: [
{title: '#', field: 'uid', sortable: true},
{title: 'Date', field: 'date_at', sortable: true},
{title: 'Nombre', field: 'name', sortable: true},
{title: 'Precio', field: 'total_price', sortable: true},
{title: 'Action', field: 'action', tdComp: 'Opt'},
],
data: [],
total: 0,
selection: [],
query: {},
}`enter code here`
},
Where Opt:
import actionItem from "../xxx.vue";
import DisplayRow from "../Utils/nested-DisplayRow.vue";
components: {"Opt": actionItem, , 'DisplayRow': DisplayRow},
So in your ActionItem component you can create your component, that component will be your row action.

Related

hide a column in vue database using checkbox

I made some code that hides a column by clicking on a checkbox and saves the changes to localstorage. The data is coming from a database so I have only 1 row line. My issue is when I refresh the page the header info is hiding itself which is good, but the rest of the lines are coming back. I would like to hide all of the column not just the header.
You can see on the image only the headers are not there after refreshing the page.
mounted() {
// "data-control-column" is a custom data attribute added to the html checkboxes
// when a check box changes loop through all, for any that are unchecked, add that checkbox's "data-control-column" value to our array
$('.opt').change(function(){
var states = [];
$('.opt').each(function(){
if(!$(this).is(':checked')) states.push($(this).data('control-column'));
});
setSates(states);
});
// when we need to set the sate of the UI, loop through the checkboxes checking if their "data-control-column" are in the "states" array
// if so, hide the specified column and uncheck the box
function setSates(states){
if(states){
if(!$.isArray( states )) states = JSON.parse(states); // if sates came from localstorage it will be a string, convert it to an array
$('.opt').each(function(i,e){
var column =$(this).data('control-column');
if($.inArray( column, states ) == -1){
$(this).attr('checked', true);
$('#myTable td:nth-child('+column+'), #myTable th:nth-child('+column+')').show();
}
else{
$(this).attr('checked', false);
$('#myTable td:nth-child('+column+'), #myTable th:nth-child('+column+')').hide();
}
});
localStorage.setItem('states', JSON.stringify(states));
}
}
// this will read and set the initial states when the page loads
setSates( localStorage.getItem('states') );
},
My database:
data() {
return {
hidePreLoader: true,
price: '',
purchase_price: '',
selling_price: '',
products: {},
tableOptions: {
tableName: 'products',
columns: [
{
title: 'lang.item_image',
key: 'image',
type: 'images',
source: '/uploads/products',
imagefield: 'imageURL',
sortable: false,
},
{title: 'lang.attribute_values', key: 'attribute_values', type: 'text', sortable: true},
{title: 'lang.quantity', key: 'test', type: 'text', sortable: true},
{title: 'lang.barcode', key: 'bar_code', type: 'text', sortable: true},
{title: 'lang.sku_2', key: 'sku_2', type: 'text', sortable: true},
{title: 'lang.sku_3', key: 'sku_3', type: 'text', sortable: true},
{title: 'lang.sku_4', key: 'sku_4', type: 'text', sortable: true},
{title: 'lang.selling_price', key: 'selling_price', type: 'text', sortable: true},
{title: 'lang.receiving_price', key: 'purchase_price', type: 'text', sortable: true},
],
formatting : ['selling_price','purchase_price'],
source: '/products/variantDetails/' + this.id,
},
}
},
and the checkbox:
<input type="checkbox" checked="checked" data-control-column="1" class="opt" />{{ trans('lang.item_image') }}

How to adjust datatables DOM elements

I have 2 questions:
Anyone knows how to make the search bar and label in one line? (red circle) Currently its 2 lines.
Preferably using the dom attribute, if possible. Or any other simple and quick method.
How to remove the space between table header and body? (yellow space). css, js methods are welcomed!
Here's my datatables initialization:
table = $('#serviceItemList').DataTable({
processing: true,
serverSide: true,
scrollResize: false,
scrollY: 300,
scrollCollapse: true,
paging: false,
info: false,
createdRow: function (row, data, dataIndex) {
$(row).attr('data-id', data.id);
},
dom: 'Bfrtip',
ajax: {
'url': "/serviceitem/list",
'type': "POST",
'data': function (data) {
data.zone = zone;
}
},
columns: [
{ data: 'checkbox', name: 'items[]' },
{ data: 'DT_RowIndex', name: 'DT_RowIndex' },
{ data: 'zone', name: 'zone', orderable: true, },
{ data: 'code', name: 'code', orderable: true, },
{ data: 'description', name: 'description', searchable: true },
],
select: {
style: 'multi',
selector: 'td:first-child'
},
});
you can try it by inspecting the element and look for its class name and then you can set the display property to none
and for the search bar do the same and set the float property to left

Client side Sorting with server side Pagination in Quasar

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.

data table columns data not display in mobile

I am using datatables and it working fine in desktop but in mobile there is no data load to table. What is the problem?
Here is my code:
$('#users-table').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
scrollY: 300,
destroy: true,
processing: true,
serverSide: true,
responsive:true,
ajax: '/depart/get_datatable/',
columns: [
{ data: 'depart_name', name: 'departs.depart_name' },
{ data: 'levels', name: 'departs.levels' },
{ data: 'name', name: 'colleges.name' },
{ data: 'action', name: 'action',searchable:false, sortable: false,
className: 'text-right' }
]
});
the solution is add cache :false to ajax call
ajax:{
url:......,
cache:false
}

Can't get my data from a store to load in the view

I'm new to Sencha Touch2 and I'm trying to start off my app by loading arbitrary data from a simple store before I go on to using a proxy. My view shows but the data is not populating. I've seen this question but nothing that has helped me solve. Any help and patience is appreciated. Thanks in adavance!
My Model
Ext.define('SenchaFirstApp.model.Distributors', {
extend: 'Ext.data.Model',
config: {
fields: [
{name: 't', type: 'string'},
{name: 'distr', type: 'string'},
{name: 'group', type: 'string'},
{name: 'site', type: 'string'},
{name: 'status', type: 'string'},
{name: 'actuve', type: 'string'},
{name: 'assigned', type: 'string'},
{name: 'state', type: 'string'},
{name: 'schedule', type: 'string'},
{name: 'finished', type: 'string'} ],
}
});
My View
var distrStore = Ext.create('SenchaFirstApp.store.DistributorStore');
Ext.define('SenchaFirstApp.view.DistributorView', {
extend: 'Ext.dataview.DataView',
requires: [distrStore, 'Ext.data.Store', 'Ext.dataview.List'],
model: 'SenchaFirstApp.model.Distributors',
xtype: 'mainlist',
fullscreen: true,
config:
{
fullscreen: true,
layout: 'fit',
border: 5,
title: 'Distributors',
html: 'My datalist',
autoLoad: true,
items:{
title: 'Setup',
xtype:'list',
store: distrStore,
fields: [
{
text: 'T',
width: 1,
sortable: false,
hideable: false,
dataIndex: 't'
},
{
text: 'Distributor',
width: 50,
sortable: false,
hideable: false,
dataIndex: 'distr'
},
{
text: 'Group',
width: 20,
sortable: false,
hideable: false,
dataIndex: 'group'
},
{
text: 'Site Name',
width: 20,
sortable: false,
hideable: false,
dataIndex: 't'
},
{
text: 'Status',
width: 5,
sortable: false,
hideable: false,
dataIndex: 'status'
},
{
text: 'Active',
width: 5,
sortable: false,
hideable: false,
dataIndex: 'active'
},
{
text: 'State',
width: 2,
sortable: false,
hideable: false,
dataIndex: 'state'
},
{
text: 'Scheduled',
width: 10,
sortable: false,
hideable: false,
dataIndex: 'schedule'
},
{
text: 'Finished',
width: 10,
sortable: false,
hideable: false,
dataIndex: 'finished'
}
]
}
}
});
distrStore.load();
My Store
Ext.define('SenchaFirstApp.store.DistributorStore', {
extend: 'Ext.data.Store',
requires: ['SenchaFirstApp.model.Distributors', 'Ext.dataview.DataView'],
config: {
// xtype: 'distrlist',
storeId: 'mainlist',
model: 'SenchaFirstApp.model.Distributors',
autoLoad: true,
data: [
{t: 'S', distr: 'Smart Systems', site: 'Smart Temps', status: "done", active: 'Yes', assigned: 'Me', state: 'IN', schedule: 'today', finished: 'today'},
{t: 'I', distr: 'People', site: 'This One', status: "done", active: 'Yes', assigned: 'You', state: 'NC', schedule: 'yesterday', finished: 'tomorrow'}
]}});
app.js
Ext.Loader.setConfig({enabled:true});
Ext.application({
name: 'SenchaFirstApp',
stores: ['DistributorStore'],
models: ['Distributors'],
views: ['DistributorView'],
requires: ['SenchaFirstApp.view.DistributorView', 'Ext.dataview.DataView', 'SenchaFirstApp.model.Distributors', 'SenchaFirstApp.store.DistributorStore', 'Ext.dataview.List'],
launch: function() {
Ext.fly('appLoadingIndicator');
Ext.Viewport.add(Ext.create('SenchaFirstApp.view.DistributorView'));
}
});
You do not need to create an instance of your store:
var distrStore = Ext.create('SenchaFirstApp.store.DistributorStore');
Because when you define your store in your application...
Ext.application({
stores: ['DistributorStore'],
...
});
...it is automatically created for you. To get a reference of your store in your view, simply use a string with the name:
{
xtype: 'list',
store: 'DistributorStore',
...
}
Other notes
You also do not need to load it using .load() because you have set autoLoad to true in your store config.
Your view should extend Ext.Container, not Ext.dataview.DataView. DataView is used to show data (basically an abstract Ext.List. Because you have a list as an item, you can just put it inside a container.
You have set fullscreen: true on the class as well as in the config. You only need to put it inside the config - but it isn't really neccessary because you are creating and inserting your view into Ext.Viewport (in your app.js) which is already fullscreen.
You do not need fields config inside your list. You should use a itemTpl to create the template for each row.