I am trying to load a dynamic data using tabulator I can generate table and data using this code:
$("#example-table").tabulator({
layout:"fitColumns",
columns:[ //Define Table Columns
{title:"Name", field:"name", width:150},
{title:"Age", field:"age", align:"left", formatter:"progress"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
],
});
var tabledata = [
{id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
{id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
{id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
{id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
{id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
];
// $("#example-table").tabulator("setData", []);
$("#example-table").tabulator("setData", tabledata);
But when I am trying to reload same data onclick function I am getting error:
Options Error - Tabulator does not allow options to be set after initialization unless there is a function defined for that purpose
So my question is how to empty data of table and reload new data or same data
The accepted answer on this is a bit overkill, you can call the setData and setColumns functions at any after the table is created. there is no need to destroy it first
//update columns and data without destroying the table
$("#example-table").tabulator("setColumns", res["column"]);
$("#example-table").tabulator("setData", res["data"]);
I guess you want to populate your table with new data for that you need to empty the data of current table for that you need to see this link:
Tabulator Discussion
Here olifolkerd is saying that you could either reinitialise the grid, by destroying it and recreating it using:
$("#example-table").tabulator("destroy");
$("#example-table").tabulator({...});
If you want to check if table is empty of not use this jquery to check if tabulator data is active or not:
var j = $( "#example-table" ).hasClass( "tabulator" )
if (j) {
$("#example-table").tabulator("destroy");
}
//set new columns
$("#example-table").tabulator("setColumns", res["column"]);
//set new data
$("#example-table").tabulator("setData", res["data"]);
I think this will solve your problem.
A function is defined for that purpose. You can use replaceData method with array of data. Or you can clear table data and add a fresh dataset.
table.clearData();
table.updateOrAddData([{id:1, name:"bob"}, {id:3, name:"steve"}])
.then(function(rows){
//rows - array of the row components for the rows updated or added
//run code after data has been updated
})
.catch(function(error){
//handle error updating data
});
//Replace Data
table.replaceData(tableData)
.then(function(){
//run code after table has been successfuly updated
})
.catch(function(error){
//handle error loading data
});
more on this here.
[http://tabulator.info/docs/4.0/update][1]
Related
I am trying to add a search filter for a custom line item field in a suitelet and it is returning no results.
function getExpenseSearch(soNum){
log.debug('getExpenseSearch entered')
log.debug('soNum: ' + soNum)
var billSearch = search.create({
type: 'transaction',
filters: [
[ 'type', search.Operator.ANYOF , ['VendBill']], 'and',
['mainline', search.Operator.IS,['F']], 'and',
['custcol_connected_so', search.Operator.ANYOF, [soNum]] ///<=== this is the problem why is it not registering?
],
columns: ['trandate',
'tranid',
'amount'
]
}).run().getRange({start: 0, end: 100})
log.debug('return billSearch[0].tranid: ' + billSearch[0].tranid) //<== always undefined
return billSearch
}
I have isolated the problem to the sublist field
custcol_connected_so is a List field (of sales orders)
soNum is the netsuite internal id of the record
I have already tried the following:
changed .IS to to .ANYOF
used TEXT value instead of recID
hardcoded the correct recID
used 'expense.custcol_connected_so (and other variations, shot in the dark)
input different syntax for create filter
In the records browser there is no join table for the vendorBill so I would think just the custcol_connected_so filter should work fine.
Taking another look there are a couple of issues.
Your syntax for getting the tranid is incorrect (or at least not supported) and you would not be able to get the mainline amount with a single query because you are only going to be able to return the line level amount. In the example below you could use ref.id to load the sales order or to do a lookup Fields call:
This works in my account:
require(['N/search'], search=>{
search.create({
type:'creditmemo',
filters:[
['mainline', 'is', 'F'], 'AND',
['custcol_linked_transaction', 'anyof', [2403605]]
],
columns:['tranid', 'custcol_linked_transaction']
}).run().each(ref=>{
console.log(ref.id, ref.getValue({name:'tranid'}), ref.getValue({name:'custcol_linked_transaction'}));
return false;
});
});
If soNum is the visible sales order number you'd need to get the SO's internal id in order to run that search. Consider:
function getExpenseSearch(soNum) {
log.debug('getExpenseSearch entered')
log.debug('soNum: ' + soNum)
var soInternalId = null;
search.create({
type: 'salesorder',
filters: ['tranid', 'is', soNum]
}).run().each(function(ref) {
soInternalId = ref.id;
return false;
});
var billSearch = search.create({
type: 'vendorbill',
filters: [
['mainline', 'is', 'F'], 'and',
['custcol_connected_so', 'is', soInternalId] ///<=== this is the problem why is it not registering?
],
columns: ['trandate',
'tranid',
'amount'
]
}).run().getRange({
start: 0,
end: 100
})
log.debug('return billSearch[0].tranid: ' + billSearch[0].tranid) //<== always undefined
return billSearch
}
i need to reflect the credit applied sublist data in my printout suitelet
but when i get the line count for credit line( var itemCount_credit = billPayRec.getLineCount({ 'sublistId': 'credit' }); ), system logs line count as -1.
Is there any way to fetch this data and if its possible from search than any suggestion what filters / columns woul i require to include?
Unless you are able to intercept the request, no. They keep this information obfuscated and by the time it has reached the sublist, it's just cached data. You could get some of the field data with inspect element but likely only what you can see.
Since you are using a Suitelet you can extract the credits applied as follows. This was run in the console but the core of it would work in a SS2.1 script. Convert ()=>{ functions to function(){ for SS2.0
require(['N/search'], search=>{
const appys = [];
search.create({
type:'vendorbill',
filters: [
[ 'internalid', 'is', 'your vendor bill internalid']
],
columns:[
'tranid',
'applyinglinkamount',
'applyinglinktype',
'applyingtransaction'
]
}).run().each(ref=>{
if(ref.getValue({name:'applyingtransaction'})) appys.push(ref.getValue({name:'applyingtransaction'}));
const c = ref.columns;
c.forEach(c=>{
const v = ref.getValue(c);
if(!v) return;
console.log(c.name, v);
});
console.log('');
return true;
});
search.create({
type:'transaction', // or just vendorcredit for you original question
filters:[
['internalid', 'anyof', appys], 'AND',
['mainline', 'is', 'T']
],
columns:['tranid'] // plus any columns of interest.
}).run().each(ref=>{
// if filtering type:'transaction' you'll get a mix of vendorcredit, vendorpayment, journalentry
console.log(ref.recordType, ref.getValue({name:'tranid'}));
return true;
});
});
I am using tabulator Tabulator to load a table using ajax.
var table = new Tabulator("#example-table", {
ajaxURL:"http://www.getmydata.com/now", //ajax URL
autoColumns: true,
});
It loads perfectly but doesn't load the first row as column headings. I need autoColumns to be set to true, because the ajax response is dynamic and the columns change. However the first row is always column headings. Tabulator is not picking up first row as heading.
I could not find relevant config to set first row as header.
If you are using the autocolumns option, tabulator will pickup the column names from the data property names on the first row, not from an array of strings on the first row.
For example, with the data below:
var tabledata = [
{id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
{id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
{id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
{id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
{id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
];
you would end up with 4 columns titled "name", "age", "col" and "dob".
Data must always be provided to Tabulator in this array of objects format regardless of how you are planning on using it.
If your server cannot provide data in this format, then you can use the ajaxResponse callback to take the incoming data from your server, reformat it, then return it from the function in the format Tabulator is expecting:
var table = new Tabulator("#example-table", {
ajaxResponse:function(url, params, response){
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
return response.tableData; //return the tableData property of a response json object
},
});
Full details on this can be found in the [Ajax Documentation[(http://tabulator.info/docs/4.9/data#ajax)
I am using Tabulator for client-side entry and editing of tabular data. In my application I have need to copy the data from a single [Crew Leader] table to one or more [Crew Member] tables. After data for the [Crew Leader] is entered I am making use of a button to trigger the copying process to the [Crew Member] tables. This is accomplished using the Tabulator setData() function which works as expected.
After data has been copied to the [Crew Member] tables it is necessary to edit each row with information pertinent to the individual [Crew Member]. The on-screen editing process works as expected.
My problem arises when I go to export the data. Note, the data in my JSON string:
is not the same as what appears on-screen; and
is the same for all [Crew Member] tables.
It appears the changes being applied to one [Crew Member] table are being applied (in the virtual DOM) to all [Crew Member] tables. Stated differently, with two "cloned" tables the changes applied to table one are applied to table two in the virtual DOM but not on-screen (and vice versa).
Client-side script which does the copying from the [Crew Leader] table to the [Crew Member] table(s):
function CloneTable() {
var tableCrewLeader = Tabulator.prototype.findTable('#CrewLeaderTable')[0];
var dataCrewLeader = tableCrewLeader.getData();
if (tableCrewLeader.getDataCount() > 0) {
// Verify a Tabulator table is present for each selected [Crew Member] by
// looping through each <div> element with the class "crew-member-card".
$(".crew-member-card").each(function () {
if ($(this).attr('id').length > 0) {
const divId = "#" + $(this).attr('id').replace('Card', 'Table');
const tableMember = Tabulator.prototype.findTable(divId);
if (tableMember.length > 0) {
const tableCrewMember = Tabulator.prototype.findTable(divId)[0];
tableCrewMember.setData(dataCrewLeader);
}
else {
console.log("The Tabulator table " + divId+ " was not found.");
}
}
});
}
}
It is also worth noting, these anomalies do not occur when the data for the [Crew Member] tables is entered directly (no setData() method is used). On-screen edits/changes are not reflected in other tables when data was not copied to the table originally.
For what it's worth, the following is the loop I use to verify the contents of each [Crew Member] table row (using Firefox Web Console to view the log):
var dataCrewMember = tableCrewMember.getData();
$(dataCrewMember).each(function () {
console.log(this);
});
EDIT
I have eliminated the disparity between the on-screen data and the exported data by setting the reactiveData attribute in my Tabulator constructor, as follows:
var table = new Tabulator(divid, {
height: "100%",
layout: "fitDataFill",
reactiveData: true, //enable reactive data
movableRows: true,
tabEndNewRow: true,
rowContextMenu: myActionContextMenu,
keybindings: {
"navUp": true,
"navDown": true,
},
columns: [
{ title: "Phase Code", field: "Phasecode", width: 144, editor: "select", editorParams: { values: function (cell) { return window.laborPhaseCodes; } } },
{ title: "Date Worked", field: "DateComp", hozAlign: "center", sorter: "date", editor: dateEditor },
{ title: "Start Time", field: "TimeStart", hozAlign: "center", sorter: "time", editor: timeEditor },
{ title: "Finish Time", field: "TimeFinish", hozAlign: "center", sorter: "time", editor: timeEditor },
{ title: "Memo", field: "Memo", width: 144, hozAlign: "left", editor: "input" },
{ title: cloneString, headerSort: false, headerClick: CloneTable, rowHandle: true, formatter: "handle" }
],
});
Note, however, I am still experiencing the issue wherein a change made in one [Crew Member] table is automatically replicated within the other [Crew Member] tables. This only happens when the data in the [Crew Member] tables has been populated using the setData() method.
Any assistance is greatly appreciated.
Inside of your cloneTables function, you set dataCrewLeader = tableCrewLeader.getData(). Then you use dataCrewLeader as the value in each of the newly created tables. I can only assume that these are being passed as a reference because they are objects. So, changing one changes them all. (I don't know if this is a bug or if it is expected that tabulator create copies when calling setData().)
To fix this, instead of setting a variable to the value. You want to call .getData() multiple times. So, you could do tableCrewMember.setData(tableCrewMember.getData()) and it will work as expected.
You can comment/uncomment the lines inside of the copyData function from the below example to see the issue.
Edited the example, so that it works without changing anything.
https://jsfiddle.net/nrayburn/85ecbvys/36/
hello am using grid to display dynamic data dojo, but what I get is that sample (n) times, but always shows me the last record, but if I do it with dummy data works well, I hope you help me with this issue.
define(["js/module/modControllerPersona", "dojo/store/Memory", "gridx/Grid", "gridx/core/model/cache/Sync", "dojo/data/ObjectStore"],
function(modControllerPersona, Store, Grid, Cache, ObjectStore){
var grid, store, data;
var persona = new Array();
return{
datagridx: function(){
modControllerPersona.persona().then(function(result){
persona = JSON.parse(result);
data = persona.items;
store = new Store({data: data});
var columns = [
{name: 'id', field: 'descripcion'},
{name: 'descripcion', field: 'id_Maquinaria'},
{name: 'descripcion', field: 'id_tipo_Maquinaria'},
{name: 'Nombre', field: 'kind'},
{name: 'Nombre', field: 'nombre'},
{name: 'Nombre', field: 'visible'}
];
grid = new Grid({
cacheClass: Cache,
store: store,
structure:columns
}, 'gridNode');
grid.startup();
});
Perhaps this can help you, I had a similar problem. If you don't have a column id it doesn't work right. But if you adjust your store to something like this:
var store = new Memory({
data: data,
idProperty: 'descripcion'
});
Perhaps the "new Memory" is not necassary. In my case this works (but I didn't tested it here again). I have no id but I have another unique field instead of this. I suppose it is because of your
{name: 'id', field: 'descripcion'}
If you use instead of "descripcion" the name "id" I think it should work too.
Just add "idProperty" for Gridx, I solved my problem
My dynamic data:
var data = [{"ID":"1","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"11.6","ITS":null},{"ID":"2","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code - UT","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"4.6","ITS":null},{"ID":"3","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"15.15","ITS":null}];
require([
'dojo/store/Memory',
'gridx/Grid',
'gridx/core/model/cache/Sync'
], function (Memory, Grid, Cache) {
var store = new Memory({
data: data,
idProperty: 'ID'
});
Hope this help