After Table Has Been Filtered, Get Hidden Column Value and Make a Global Variable
After Table Has Been Filtered, Get Hidden Column Value and Make a Global Variable
Hello,
I have the following filter for my DataTable to only show Items that have a date within the current week.
$.fn.dataTable.ext.search.push( //creating my own filter function for the table
function(settings, searchData, index, rowData, counter, statusClass) {
var now = moment(); //creating another now variable which is an instance of the current date
var monday = now.clone().weekday(1); //creating an instance of the current week Monday Date
var friday = now.clone().weekday(5); //creating an instance of the current week Friday Date
let mondayF = monday.format('MM/DD/YYYY'); //formatting the monday date to MM/DD/YYYY
let fridayF = friday.format('MM/DD/YYYY'); //formatting the friday date to MM/DD/YYYY
var sMonday = searchData[2]; //created a var to search through the 3rd column (0 index) which contains all of the Monday Dates
var sFriday = searchData[10]; //created a var to search through the 11th column (0 index) which contains all of the Friday Dates
// Get Datatables API
var api = $.fn.dataTable.Api('#myTable');
if (mondayF == sMonday && fridayF == sFriday) {
$('#under_txt').html("Week Of: " + moment(mondayhead).format("MMM Do YYYY")); //applying the monday date of the current week back to the #under_txt after the search is cleared
return true;
}
// Does row contain the search term? If so it will show searched data outside of the current week and only items within the week of the date searched
if (searchData.includes(api.search())) {
$('#under_txt').html("Week Of: " + moment($('#dpicker').val()).startOf('isoWeek').format("MMM Do YYYY")); //applying the searched date value to the #under_txt
return true;
}
//if current monday = monday in table, only show that. Same for the friday value
return false;
}
);
This returns the exact values I want to display in the table. I have an external REST call that I am trying to filter by dates, but it doesn't work due to some user's time zone. But the filter works fine for those users, so I have created a hidden column value to pull the list item ID through that is tied to all of the information. Is there a way I can get that column value globally to append to the end of my REST API openDialog()?
Lets say the column is like as below,
{"data" : "ListItemID", visible: false},
and below is what I need to append that filtered ListItemID value to. This open dialog is in the .done() success function of an Ajax call.
openDialog('/sites/Projects/Report/Lists/Report/EditForm.aspx?Id=' + [Insert ListItemID Here])
Answers
You can use
row().data()
,column().data()
orcell().data()
to get the data from that column. Does the column contain the same value for each row? If not how do you know row to use for the REST API call?Kevin
Hey Kevin,
It does not contain the same ID. But I will filter the rows to only search for data in the row where the first column matches the current signed in user's name