'How can I get all IDs by grid grouping?
I have a Kendo UI grid that is populated by Ajax query to an api. The grid has column for sample IDs, status (if document is generated or not) and a button to generate the document (if not already).
I am implementing a button to generate documents for all sampleIds in one go and need to fetch the IDs of remaining ones.
And I group the IDs based on status like this:
dataSource.fetch(function(){
var view = dataSource.view();
console.log(view.length);
console.log(view[0]);
});
I want to implement a function that gets all the IDs (with status 'F' ) and generate documents for them. How do I get this view array in the function?
I tried this but it says datasource is undefined.
<button id='RegenerateButton' onclick=regenerateAll()>Regenerate All</button>
function regenerateAll(){
dataSource.fetch(function(){
var view = dataSource.view();
console.log(view.length);
console.log(view[0]);
});
}
My dataSource is defined like this:
$(document).ready(function () {
var crudServiceBaseUrl = window.location.origin + "/api",
dataSource = new kendo.data.DataSource
({
type: "json",
serverPaging: true,
serverSorting: true,
serverFiltering: true,
allowUnsort: true,
pageSize: 10,
group:{field:"Status"},
transport: {
read: {
url: crudServiceBaseUrl + "/HL7Message/getListOfProcessedData/",
dataType: "json",
.....
Solution 1:[1]
The first change you will want to make is to get the data source's data (documentation) and not the view.
In terms of grouping the data you will need to do the following:
- Get the data
- Filter the data by its status field
- Map the data to get its id field
- Get just the unique values from the mapped/filtered values
Here is an example:
const everyId = dataSource.data()
.filter(row => row.Status === 'F')
.map(row => row.Id);
const uniqueIds = [...new Set(everyId)];
In terms of the datasource variable being undefined, I will need to see a bit more code. There are two possibilities I can think of:
- You have a typo and the datasource variable is named something else
- The datasource lives in a different context (i.e. scope) than where you're trying to access it from
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David |
