Filtering externally hosted GEOJSON data to not show certain results

Filtering externally hosted GEOJSON data to not show certain results

[Deleted User][Deleted User] Posts: 0Questions: 3Answers: 0

Hi There,

I'm wondering if it's possible with the filter API to limit shown results in column 4 to not show files ending with .txt

$(document).ready(function() {
var table = $('#example').DataTable( {
var filteredData = table
.column( 4 )
.data()
.filter( function ( value, index ) {
return value != "*.txt") ? true : false;
}
"ajax":{
"url":"https://opendata.arcgis.com/datasets/TheFile.geojson",
"dataSrc": "features"
},
"columns": [
{ "data": "properties.BoreholeId"},
{ "data": "properties.ArchiveId" },
{ "data": "properties.Description" },
{ "data": "properties.UNCPath" }
],
dom: 'lfrtBip',
buttons: [
'copy', 'csv'
]
});
});

Cheers

RockE

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,144Questions: 26Answers: 4,736
    Answer ✓

    The filter() API doesn't affect the Datatable rows displayed. From the docs:

    This method should not be confused with search() which is used to search for records in the DataTable - i.e. the filter method does not change the rows that are displayed in the DataTable.

    Depending on your goal and the amount of data you can use the ajax.dataSrc as a function and remove the appropriate data by iterating the JSON response.

    Another option is to simply use the search to set the initial search fo the table to filter those rows. The rows are still in the table and shown as part of the table info element. They potentially could be unfiltered and shown in the table.

    If you don't want the data at all then I would look for options to have the hosted side return the data as needed.

    Kevin

  • [Deleted User][Deleted User] Posts: 0Questions: 3Answers: 0

    Thanks Kevin, I'll check out these option.

This discussion has been closed.