We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Loop data/rows in grid

How to read all rows of my grid depending on the page in which we are and store them in my model (user.model)?

Thanks

7 Replies

PS Pavithra Subramaniyam Syncfusion Team May 13, 2019 05:52 AM UTC

Hi Jesus, 
 
Thanks for contacting Syncfusion support.  
  
You can read the current page records by using  the “grid.currentViewData” property. Please refer to the below code example, documentation link and sample link for more information. 
 
[component.ts] 
@Component({ 
    selector: 'app-root', 
    template: '<button (click)="click($event)">Read records</button> 
    <ejs-grid #grid [dataSource]='data' allowPaging='true' height=365 [pageSettings]='initialPage'> 
        <e-columns> 
           .  .  . 
        </e-columns> 
    </ejs-grid> 
' 
}) 
export class AppComponent { 
    @ViewChild('grid') 
    public grid: GridComponent; 
 
    ngOnInit(): void { 
        this.data = data; 
        this.initialPage = { pageSizes: true, pageCount: 4 }; 
    } 
    click(e){ 
     console.log(this.grid.pageSettings.currentPage); 
     console.log(this.grid.currentViewData);            // here you can store the records in your model 
    } 
} 
 
                              https://ej2.syncfusion.com/angular/documentation/api/grid/pageSettingsModel/#currentpage 
 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 



JS Jesus Sanchez May 13, 2019 06:51 AM UTC

Thanksssss!!!!


PS Pavithra Subramaniyam Syncfusion Team May 13, 2019 09:12 AM UTC

Hi Jesus, 
 
As always, we will be happy to assist you. 
 
Please contact us if you need any further assistance.  
 
Regards, 
Pavithra S. 



JS Jesus Sanchez May 13, 2019 01:09 PM UTC

A question, advice ... imagine that we have stored images on the server site. In the example that you have: https://ej2.syncfusion.com/angular/demos/#/material/grid/column-template, if I wanted to recover the images of the site, how could I do it ???


PS Pavithra Subramaniyam Syncfusion Team May 15, 2019 08:44 AM UTC

Hi Jesus, 

Thanks for the update. 

You can achieve your requirement by using the below way. 

Note: First You have to store the images in server as byte array. 

Step #1: You need to convert the byte array to base64 string. You can achieve this requirement like as following code snippet,  

string base64String = Convert.ToBase64String(bytes, 0, bytes.Length); // Convert the bytes to base64 string  

 

Step #2: You need to add this converted base64 string with Grid data source.  

Step #3: When you display the image in Grid to column, you need to convert this base64 string to image. We suggest you to use queryCellInfo event of the Grid to achieve this requirement. Please refer the following code snippet,  

function queryCellInfo(args) { // Grid queyCellInfo event  
        if (args.column.field == "Image") {  
           var image = new Image();  
            image.src = "data:image/png;base64," + args.data.Image; // base64 string  
            args.cell.appendChild(image); // Appended the image to particular cell  
        }  
    }  

 

In this code we have converted and appended the based64 string to Grid cell with the help of Grid queryCellInfo event. You can access the base64 string in this queryCellInfo event argument(i.e args.data). 


Please get back to us if you need further assistance. 
 
Regards, 
Pavithra S. 



JS Jesus Sanchez May 16, 2019 08:30 AM UTC

Thanks ... now work it!!!!


PS Pavithra Subramaniyam Syncfusion Team May 16, 2019 09:41 AM UTC

Hi Jesus,  

Thanks for your update. 

We are happy to hear that the provided solution works. 

Please contact us if you need any further assistance. As always, we will be happy to assist you.  

Regards,  
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon