Creating dynamic ColumnDefs for UI Grid is essential for responsive and flexible data

I am currently facing a challenge with my angular UI Grid setup for populating data in reports. With almost 20 reports to handle, I am looking to streamline the process by using one UI Grid for all of them. To achieve this, I am attempting to dynamically configure the columnDefs property at runtime by iterating through the properties of an object.

CrudService.GetData($scope.studyId, reportsTest).then(function (data) {
    $scope.getreportsdata = data;
    $scope.columns = [];
    for (var key in $scope.getreportsdata[0]) {
        if ($scope.getreportsdata[0].hasOwnProperty(key)) {
            if (!utilityExtensionService.isUndefinedOrNull($scope.getreportsdata[0][key]) && $scope.getreportsdata[0][key] != "")
                $scope.columns.push({ field: key, enableSorting: false, headerCellClass: 'ui-grid-header' });
        }
    }
});

This is how I am trying to set up my UI Grid:

$scope.gridOptions = {
            enableHorizontalScrollbar: 0,
            enableVerticalScrollbar: 0,
            enableSorting: true,
            columnDefs: 'columns',
            data: 'getreportsdata'}

Unfortunately, I have not been successful in binding using this approach. Any recommendations or alternative solutions would be greatly appreciated.

Answer №1

Your grid configuration is not correct.

$scope.gridOptions = {
   enableHorizontalScrollbar: 0,
   enableVerticalScrollbar: 0,
   enableSorting: true,
   columnDefs: $scope.columns,
   data: $scope.getreportsdata
}

In the future, it would be advisable to recreate the problem on a Plunkr link for better understanding.

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

How can we display all products from a database on an online shop using Angular and node.js? The controller is not functioning as expected

My backend is built with node, while the frontend uses angular to display products. However, I'm facing an issue where nothing is being displayed. The database setup is Postgres (Sequelize) and everything seems to be working fine. After examining vari ...

Why isn't my data appearing when using $http.get in AngularJS?

I'm encountering an issue where my bar graph doesn't display data when using $http.get. However, if I eliminate $http.get and directly call the URL, the data shows up perfectly. Any suggestions on what might be causing this problem? AngularJS v ...

What is the best method for showing jQuery/Javascript functions in the HTML <pre> element as a string

I am curious about converting jQuery or JavaScript functions to a string and displaying them in an element like <pre> HTML : <pre></pre> jQuery : function test() { alert('test'); } $('pre').html(test()); // &l ...

Verify if the form has been refreshed in React JS

In my React application, I have a form inside a modal pop-up. When the user closes the pop-up, I want to check for any changes made in the form fields. If there are changes, I will display a confirmation modal; if not, I will simply close the pop-up. <F ...

Error thrown in Node.js ReadSync call due to buffer length overflow

I am working on generating RTP packets for an MJPEG video. My process involves reading the first 5 bytes of the file to determine the frame length, and then reading that specified size. Below is the code snippet I have implemented: while(totalSiz ...

List being dynamically split into two unordered lists

Could someone help me with a JS/jQuery issue I'm facing? My challenge is to populate a modal when a link is clicked. Upon clicking the link, a UL is created from a data attribute. However, the problem is that only one UL is being generated whereas I ...

Obtaining the "match" object within a Custom Filter Selector on jQuery version 1.8

Here's a helpful resource on Creating a Custom Filter Selector with jQuery for your reference. A Quick Overview: If you're unfamiliar with jQuery's Custom Filter Selectors, they allow you to extend jQuery’s selector expressions by addi ...

Sentry platform is failing to record network-related problems

Incorporating Sentry into my Next.JS application has allowed me to easily detect JavaScript errors such as reference or syntax issues on the Sentry platform. Unfortunately, I have encountered some challenges as Sentry is not logging any network-related er ...

JavaScript Elegance: Error Encountered - Unable to Locate Property 'index of' of an Undefined Value

As I delve into learning JavaScript through Eloquent Javascript, I encountered an error in one of the chapters that has me stumped. The error message "Cannot read property 'indexOf' of undefined" is appearing with this line of code: re ...

Encountered an error when attempting to use 'appendChild' on 'Node': the first parameter is not the correct type. It was able to work with some elements, but not with others

I'm currently working on a script that utilizes fetch to retrieve an external HTML file. The goal is to perform some operations to create two HTMLCollections and then iterate over them to display a div containing one element from each collection. Here ...

Modify a property within an object and then emit the entire object as an Observable

I currently have an object structured in the following way: const obj: SomeType = { images: {imageOrder1: imageLink, imageOrder2: imageLink}, imageOrder: [imageOrder1, imageOrder2] } The task at hand is to update each image within the obj.images array ...

Setting up CloudKitJS Server-to-Server Communication

I'm struggling to make this work. I keep encountering the following error message: [Error: No key provided to sign] Below is my configuration code: CloudKit.configure({ services: { fetch: fetch }, containers: [{ containerIdentifier: & ...

What's the significance of the #/ symbol in a URL?

Currently, I am developing Ruby on Rails web applications. The URL of my webpage appears as follows: http://dev.ibiza.jp:3000/facebook/report?advertiser_id=2102#/dashboard From this link, I have identified that the advertiser_id is 2102 but I am unsure a ...

Could the comments within a NodeJS script be causing memory problems?

I specialize in creating NodeJS libraries, and my coding practice includes adding JSDoc comments for documentation purposes. Here is an example of how my code usually looks: /** * Sum * Calculates the sum of two numbers. * * @name Sum * @function * ...

Using Node.js to dissect a nested JSON array into individual JSON objects

Seeking guidance on how to efficiently parse nested arrays into separate objects using Node.js. Your assistance would be greatly appreciated. I aim to exclude the following from the final output- "Status": "0", "Message": "OK", "Count": "3724", AND I w ...

Developing an interactive menu for mobile devices utilizing a combination of JSON, HTML, JavaScript, and CSS

Creating a custom dynamic menu for mobile platforms using HTML, JavaScript, and CSS with a JSON object downloaded from the server. Not relying on libraries like jQuery. I've come across advice stating that "document.write" should not be used in event ...

Improving file reading and parsing efficiency with fast random access using csv-parse in Node.js

I recently encountered a challenge while working with the csv-parser library in node for parsing large CSV files. The files I work with can range from 50,000 to 500,000 lines or even larger. My task involved performing computations on this data and then su ...

Is there a way to simulate a click event within a Jasmine unit test specifically for an Angular Directive?

During the implementation of my directive's link function: $document.on('click.sortColumnList', function () { viewToggleController.closeSortColumnList(); scope.$apply(); }); While creating my unit test using Jasmine: describe(&apo ...

Is it possible to selectively process assets based on their type using Gulp and Useref?

Is it possible to selectively process css and js assets using gulp-useref based on the build type specified in the html tags? <!-- build:<type>(alternate search path) <path> --> ... HTML Markup, list of script / link tags. <!-- endbui ...

I am looking to pair a unique audio clip with each picture in my collection

I have implemented a random slideshow feature that cycles through numerous images. I am now looking to incorporate a brief audio clip with each image, synchronized with the array I have established for the random pictures. The code snippet below is a simil ...