I've searched into the documentation of data tables of how one can add data to the table here
https://datatables.net/examples/data_sources/index.html but no where I could find a way to insert data into a single cell for a given column. For example, I need sth like:
"columns": [ {target (0), "value which will be inserted"} ]
There is a way to inser data from an array but each section of the array contains values for the whole row ( see here https://datatables.net/examples/data_sources/js_array.html) but I need to insert data into different cells in respect with the columns since I don't know the column labels initially. This is because the data will be in json format and first I need to extract the unique dates for each json object. These will be my column headers. And then for each of the objects based on its date I need to put it into the relevant date column. So the logic should be sth like:
if this date column (from the table) == json object date then put it there
Thanks
It seems like after a lot of researching this feature is not available in DataTables. So that's why I've solved the problem with jQuery. Using the code below I can iterate through a column and insert values in it.
//change 1 to the column at hand
$("#table tr > :nth-child(1)").each(function(index) {
//skip the column header
if (index > 0){
//insert value
$(this).html("<span class='fixed-size-square'> value to be inserted");
}
});
Related
I'm using Google script to create a webapp.
I've got data from my google GSheet and loaded it into an array, called 'data' using javascript.
Using Tabulator, I can display the data in a table by using the autoColumns feature.
However the Table header fields are listed as 0,1,2,3 even though the first record contains the actual fields names. (Email, Status, Last Login, etc)
When I try and create my own header names, it requires the filed name - field:"xxx"
So my question - how do i find that field name....
columns:[
{title:"Email", field:"**xxx**"},
]
I've used 0,1,2,3 - didn't work
Col1, Col2, Col3, Col4 - didn't work
Not sure what else to try?
Thanks in advance.
You need to look at the array of objects you are passing into the Tabulator data property
The field value for each column is the property name in the row data object
For example if your row data object is:
{name:"steve", age:23, driver:False},
Then the column definition for the name column would be:
{title:"Name", field:"name"},
I want to check if the data is already exist in datatable in certain column but I don't know how to do it.
Heres what I tried
var issueData = $('#table').DataTable().column(2).search($('input[name=search]').val()).rows({search: 'applied'}).data().toArray();
if(issueData == '')
{
var data = [];
data.push(rowData[0]);
data.push(rowData[3]);
data.push(rowData[2]);
data.push(rowData[4]);
data.push(rowData[6]);
$('#table').DataTable().row.add(data).draw(false);
}
the problem on this is I if the issueData is empty it will just overwrite the existing data and have filter on the bottom of the datatable
here's what the filter
Showing 1 to 1 of 1 entries (filtered from 3 total entries)
I don't want to filter it I just want to check if the data is existing already on a certain column then add the data if its not existing if it exist then do nothing.
search() as you say will search the actual table. To filter it without changing the user's view of the table, use filter(). See docs here: https://datatables.net/reference/api/filter()
I am struggling to come up with a query for sqlite table to UPDATE OR INSERT at rowid. The problem I have is that I have a database where it relies on the rowid but when populating the table there may not be enough rows. So the table may look like this:
rowID data1 data2 data3
------ ------ ----- ------
0 18 1543
1 5
2 35 918
And for my query I want to be able to insert data2 = 453 at rowID = 16 for example. Also just to specify I do not have a column of rowID.
I am thinking that the only way possible would be to insert empty rows from rowID 3 -> 15 before inserting the 16th row. It does not matter for me if rows are empty as they will eventually be populated. I will not be working with more than 50 rows or more than 8 columns so it is a reasonably small table. Anyone know a way forward for me to work?
Also additional thing to note, I am using the query on Titanium, so the programming language is JavaScript.
The documentation says:
The rowid value can be accessed using one of the special case-independent names "rowid", "oid", or "rowid" in place of a column name.
[...]
An INSERT statement may provide a value to use as the rowid for each row inserted.
So just specify the values you want:
INSERT INTO MyTable(rowid, data2) VALUES(16, 453)
I have a project that consist of a function that generate a table based on some filter. Then, I found a problem that when some combination of some filter are return nothing so, when it rendered in browser as a table is less than number of combination.
To achieve it, I want to give "-" mark to the loss record that not saved in the table.
My first approach is check one-by-one the array with the filter and if the condition is match to 'loss rows', it will push array untill all missing record in result is filled with '-'. But, it'll dealing with time because, the last must be sorted again and then to be constructed into the wanted table.
Sample schema of main table "A":
amount_of_product, id_product, id_people, id_place.
The primary key columns are:
id_product, id_people, id_place.
The content of the main table is:
23456, book-a, 1, aa
5678, book-b, 1, cc
2587, book-b, 1, aa
The source query will be something like:
select * from A
where
id_product in ('book-a', 'book-b')
and id_people in ('1') and id_place in ('aa', 'bb', 'cc')
order by id_product, id_place
Then, we want to show in a table view (html) all combinations of all selected filters. 6 rows should be rendered, with empty cells shown as "-".
Sample result table:
Can I do it efficiently or are there any solution to this?
Thanks in advance.
Thanks for some advice above.
I've try to use crosstab function in postgresql to produce the pivot table but I can't produce for more complex table.
So, I use another approach to retrieve all datas based on combination row-coloumn gradually (example query from id_place 'aa', id_people '1', id-product 'aa' etc) and contruct each table head row and coloumn then contruct the data.
Regard
I am creating a table dynamically using JQuery as the number of rows in the table depends on the amount of Agents configured to a server I am pulling data from.
The statistics in the table need to be "real-time" so I am recreating the table every second with fresh statistics. I am using the JQuery TableSorter plugin - http://tablesorter.com/docs/
to allow me to make the table sortable as is one of my requirements, However every time the table is recreated this renders the sort useless. Can anyone think of a solution?
This is my code to create the table.
function addToTable() {
var agentData = getAgentStats();
var ids = getAgentIds();
var names = getAgentNames();
// Add new Row to to table
for(var i =0;i<agentData.length;i++){
$('#StatsContainer').append('<tr><td>'+ids[i]+'</td><td>'+names[i]+'</td><td>'+agentData[i].statistics[13]+'</td><td>'+agentData[i].statistics[3]+'</td>\n\
<td>'+agentData[i].statistics[4]+'</td><td>'+agentData[i].statistics[6]+'</td><td>'+agentData[i].statistics[12]+'</td><td>'+agentData[i].statistics[14]+'</td><tr>');
}
// Let table sorter know that table contents has changed
$("table").trigger("update");
}
Thank you in advance.
Without seeing more of your code to gain context:
Tablesorter supports the ability to send it controls about how you want to sort the table.
$("#trigger-link").click(function() {
// set sorting column and direction, this will sort on the first and third column the column index starts at zero
var sorting = [[0,0],[2,0]];
// sort on the first column
$("table").trigger("sorton",[sorting]);
// return false to stop default link action
return false;
});
You could intercept clicks on headers to take note of the sort order, and then call on tablesorter as demonstrated above.
Once you are intercepting how the table should be sorted you can apply that sort after every time you rebuild the table.