Is it possible to omit certain columns when extracting data from a Kendo grid?

My challenge involves extracting data from a Kendo grid using the following JavaScript call:

var data = JSON.stringify($(".k-grid").data("kendoGrid").dataSource.data())

This retrieves all properties in the C# class for the records. There are three properties that were not displayed in the Kendo presentation but are being included in this call (and subsequently passed on to an Export to CSV function).

I am seeking guidance on how to exclude these specific columns from the data extraction.

EDIT:

After reviewing @DontVoteMeDown's advice, I attempted to create a function for this purpose:

function removeKeys(data) {
    let excludedKeys = ['InvoiceId', 'IsOk', 'ErrorMessage'];
    let newData = data.map((item) => {
        let newObj = {};

        Object.keys(item).forEach(key => {
            if (excludedKeys.indexOf(key) == -1) {
                newObj[key] = item[key];
            }
        });

        return newObj;
    });
}

However, when running the code in the Console debugger, an error is encountered.

When executing the sequence like this, I face an issue with 'data' returning undefined:

var tableData = $(".k-grid").data("kendoGrid").dataSource.data();
var dataChop = removeKeys(tableData);
var data = JSON.stringify(dataChop);

By rearranging the steps as follows, I receive an error stating 'data.map is not a function':

var tableData = $(".k-grid").data("kendoGrid").dataSource.data();
var dataFull = JSON.stringify(tableData);
var data = removeKeys(dataFull);

What would be the correct approach to invoke this mapping function successfully?

Answer №1

Here is a straightforward way to implement the suggestion made by @ZorgoZ:

let information = [{
  x: 1,
  y: 2,
  z: 3
}, {
  x: 4,
  y: 5,
  z: 6
}];

let excludedValues = ['z'],
    newInformation = information.map((item) => {
      let freshObject = {};
          
      Object.keys(item).forEach(key => {
          if (excludedValues.indexOf(key) == -1) {
              freshObject[key] = item[key];
          }
      });
   
      return freshObject;
   });
   
console.log(newInformation);

Make sure that information corresponds to your dataSource.data().

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Commitments and incorporating items from an array into objects nested within a separate array

My current project involves a command line node application that scrapes valuable data from a specific website and stores it in a CSV file. For the scraping functionality, I am utilizing scrape-it, which enables me to successfully extract all the necessa ...

Does ng-include fetch the included HTML files individually or merge them into a single HTML file before serving?

Is there a performance impact when using the ng-include Angular directive, in terms of having included HTML files downloaded as separate entities to the user's browsers? I am utilizing a CDN like AWS CloudFront instead of a node server to serve the H ...

Enhancing the appearance of list options in Autocomplete Material UI by utilizing the renderOption feature

I'm putting in a lot of effort to customize the option elements in the autocomplete list. My plan is to achieve this using the renderOptions prop, where I can create DOM elements and easily apply styles with sx or styled components. However, somethin ...

I can't figure out why my SCSS isn't loading, even though I've added it to the webpack.mix.js file in my Laravel project that's set up with React.js

I'm facing a problem where my SCSS is not loading in the VideoBackground.js component of my Laravel project built with React.js, even though I have set it up correctly in the webpack.mix.js file. The file path for the videoBackground.scss file within ...

Encountered a problem during the insertion of data into the database through ajax and php

An issue is being encountered while trying to insert data into a database using Ajax, PHP, and jQuery. The code works smoothly on a localhost environment, but upon uploading it to the server, an error occurs. $('#sunsubmit').click(function(){ ...

Exploring Angular 6 with Universal Karma for effective module testing

Issue I have been facing challenges while testing my Angular 6 application with Karma. I am encountering errors such as: Can't bind to 'ngModel' since it isn't a known property of 'mat-select'. Although the import works in ...

The dynamically generated table will only show the most recently added data

Currently, I am delving into the world of JavaScript to tackle an interesting challenge. Here's the scenario: I have a dropdown list populated with stream names derived from an array. Whenever a selection in this array changes using `onchange()`, I wa ...

Make Fomantic-UI (Angular-JS) sidebar scroll independently

Is there a way to make a sidebar scroll independently of the content it pushes? Currently, my page is structured like this: -------------------------- |[button] Header | -------------------------- |S | Main content | |i | ...

What is the method for transmitting a YAML file in the form of a base64 encoded string?

I am attempting to transmit a yaml file as a base64 string in order for this code to function: const response = await octokit.request('GET /repos/{owner}/{repo}/git/blobs/{file_sha}', { owner: 'DevEx', repo: 'hpdev-content&apos ...

Can you explain how to break down secured routes, users, and posts all within a single .create() function in Mongoose/JavaScript

I am seeking guidance on utilizing the .create() method within a protected route while implementing deconstructed JavaScript. In the absence of the protected route, I can deconstruct my schema and utilize req.body in .create(...) as shown below. const { ti ...

Perform a replacement with jQuery.replaceWith() on an input field and refocus in Microsoft Internet Explorer

There exists a script http://gist.github.com/457324 which establishes default text (extracted from the element's title attribute) for empty input[type=text] as well as input[type=password] elements. However, setting default text for password elemen ...

What strategies can be employed to maintain reliable datetime management for a reservation system operating in diverse time zones?

Looking at the big picture: An interesting scenario arises when a hotel owner specifies a time frame for booking reservations at a restaurant (5pm - 10pm). Along with this information, there is also a timezone provided to ensure that dates are displayed i ...

Vue.js global event issue

Recently, I encountered an issue with the following code: <component-one></component-one> <component-two></component-two> <component-three></component-three> Specifically, component-two contains component-three. My cu ...

Exploring Nested Views in a MEAN Application using UI Router

I am currently developing a MEAN application and struggling to get my ui-router functioning correctly. Within my index.html template, I have loaded all the necessary javascript and css for my application such as angular, jquery, angular-ui-x, bootstrap. I ...

I would like to split a string of characters using spaces XY XYZ XYZ

As a young developer, I am facing a challenge and seeking a solution. The user enters a number in a format like XX XXX XXXX, but I need it to be separated differently. Currently, the numbers are being grouped as XXX XXX XXX, which is not the desired outp ...

I'm puzzled by the inconsistency of my scrolltop function on mobile, as it seems to be scrolling to various parts of the page depending on my

I am encountering an issue with a function that scrolls to a specific element when a button is clicked. Strangely, this functionality works fine on desktop but fails on mobile devices. It successfully scrolls to the correct position only when at the top of ...

Difficulty in transmitting two boolean values using ajax and setTimeout()

I am working on two functions that are supposed to send either 0 or 1 to a PHP page using AJAX. When a key is pressed on the keyboard, the function that sends 1 should start, followed by the second function that sends 0 three seconds later using setTimeout ...

Having trouble getting the .push() method in JavaScript to function correctly

I've encountered an issue while trying to develop a function that iterates through each item in an array and records the index of a specific item when found. In this particular function, whenever the item 'contraband' is detected during the ...

What is the approach to initiating a jquery function once HTML content is dynamically added through an AJAX call?

<div id="timeline"> <ul class="grow" id="grown"><li>One</li><li>Two</li><li>Three</li><li>Four</li><li>Five</li><li>Six</li><li>Seven</li><li>Eight< ...

Click on the image to resize the div accordingly

I have a scenario where I need to achieve the following functionality: Two divs are present, with an image inside the first div. When the image is clicked, the left div should resize, and the content on the right side should expand to show full page cont ...