how to get the searched data in datatable but not show it - javascript

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()

Related

SetModel for AgGrid works for a single value, but does not work for multi value

I have a problem, where I'm trying to apply a multi value filter to a column.
I have set the Column in colDefs to have filter: 'agSetColumnFilter',
With that in place, in my process I build an array of values, that I'm trying to filter on. I use this array in setModel, however it is not working. By not working, my grid basically get's cleared and there is nothing showing.
However, if I try to use the same approach, but instead only try to filter on a single value, something like arr[0], then the grid properly works and does the filtering as expected. So the filter functionality works, it just won't let me do it on multi value.
In my code, I create an array of values that I want to apply to a specific column, so let's say I have a Col1 that I'm trying to filter:
var valsToFilter=[];
valsToFilter.push('hey');
valsToFilter.push('bye');
var filterColumn = 'Col1';
var fil = grid.api.getFilterInstance(filterColumn);
fil.setModel({values:[]}];
fil.setModel({
values: valsToFilter
}); //This does not work. Grid gets cleared of everything, no rows showing.
fil.setModel({
values : valsToFilter[0]
});//but this works, shows the appropriate rows
fil.applyModel();
grid.api.onFilterChanged();

Bitrix24 injecting filter values with BX.Main.filterManager

I'm trying to change a Bitrix grid filter with javascript.
I can access the filter with BX.Main.filterManager.getById("GRID_ID"), can refresh the filter and the connected grid with .applyFilter() but I couldn't find a way to change them.
How can I get the current filters and add or remove any filters to that list?
var filter = BX.Main.filterManager.getById(BX.Tasks.GridActions.gridId);
var values = filter.getFilterFieldsValues();
// .. modify values as you wish ..
filter.getApi().setFields(values);
filter.getApi().apply();

Jqgrid: get count of rows post applying local filters

I want to get the count of all records posts applying local filters. Currently, I am getting all rows instead of filters rows.
jqgrid version= 5.3.0 free version
I tried to using lastSelectedData and data methods. lastSelectedData is giving a null record. data is giving all records. but I need to get all filtered rows.
gridElem.jqgrid.('getGridParam', 'lastSelectedData') // return null
gridElem.jqgrid.('getGridParam', 'data') //returns all records
I found the solution to this problem.
On loadComplete we are get the actual filtered count as data.records where data is parameter of loadComplete method.
I am storing that in private variable and using it.
loadComplete:(data) => {
console.log(data.records)
}

insert data into specific column cell using datatables jquery

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");
}
});

Dynamically sorted table sort lost on update

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.

Categories

Resources