The New Way to Build with AI! Introducing ReUI — the developer platform for agentic UI with shadcn/ui
Browse ReUI Pro

issue with ajax table in metronic standard template


im having table with the personalization of the ajax table in the standard metronic template for angular.
this is how i personalized the datatableConfig in my component:
this.datatableConfig = {
serverSide: false,
autoWidth: true,
lengthChange: true,
pageLength: 10,
lengthMenu: [10,25,50,100],

and in the app-crud module they are "seen" but the table isnt built with the option of choosing the lenght of the table.

Can someone help me into understanding how i could achieve the visualization of the table lenght modifier in the table?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (7)

 
Deleted comment
Deleted comment
 
Deleted comment

Hi Giacomo Cardillo

In Angular, it's generally a good practice to initialize UI-related components in ngAfterViewInit() rather than ngOnInit(). This is to make sure that the view and its elements are fully initialized before manipulating them. We will fix it from our side.



Hi Giacomo Cardillo

Sorry for the delay. With your current progress, how is the menu dropdown displaying right now?

The lengthMenu option you've defined should be correct. Please ensure that your DataTable is properly initialized and that the configuration options are being applied correctly. You can refer to the official DataTables documentation for the lengthMenu option here:



If the length menu is still not displaying, double-check the following:
- Ensure the DataTable is initialized in the ngAfterViewInit lifecycle hook.
- Verify that all necessary dependencies for DataTables are installed and correctly imported.
- Confirm that your HTML structure includes the DataTable directive and is properly set up.

If you need further assistance, please provide more details about your current setup or any specific errors you encounter.



Hi, this is how i initialize the datable in the page

ngOnInit(): void {
let self = this;
this.datatableConfig = {
serverSide: false,
autoWidth: true,
lengthChange: true,
pageLength: 10,
lengthMenu: [10,25,50,100],
ajax: (dataTablesParameters: any, callback) => {
this.userService.list(this.page,this.pageLength).subscribe(resp => {
console.log(resp);
const userList = {
draw: this.page,
recordsTotal: resp.totalRecords,
recordsFiltered: resp.usersList.length,
data: resp.usersList
}
callback(userList);
});
},
columns: [
{
title: 'Nome',
data: 'username',
orderData: [0],
orderSequence: ['asc', 'desc'],
type: 'string',
searchable: true,
render: function (data, type, full) {
return data || '';
}
},
{
title: 'Nome Completo', data: 'fullname', render: function (data, type, row) {
return data || '';
},
orderData: [1],
searchable: true,
orderSequence: ['asc', 'desc'],
type: 'string',
},
{
title: 'Indirizzo Email', data: 'email', render: function (data, type, row) {
return data || '';
},
orderData: [2],
searchable: true,
orderSequence: ['asc', 'desc'],
type: 'string',
}
],
createdRow: function (row, data, dataIndex) {
$('td:eq(0)', row).addClass('d-flex align-items-center');
},
};
}


im doing it on the ngOnInit because i saw in the template doing so, do i have to move it in the ngAfterViewInit (that right now is empty)? or i am doing something wrong in my definition?


Hi Giacomo Cardillo

For DataTables implementation server-side, you need to structure your API call to handle the parameters passed by DataTables. This involves passing the dataTablesParameters object to your backend via a POST request and ensuring the backend handles these parameters appropriately to return the subset of data.

Here is our example API call. /src/app/_fake/services/role.service.ts

dataTablesParameters need to pass into the POST request, and the backend code needs to handle it so the result return based on the length from dataTablesParameters

<pre> getRoles(dataTablesParameters?: any): Observable<DataTablesResponse> { const url = `${this.apiUrl}-list`; return this.http.post<DataTablesResponse>(url, dataTablesParameters); } </pre>

ok i knew that, but what i cannot accomplish is to render the datatables lenght with this code:

new DataTable('#example', {
lengthMenu: [
[10, 25, 50, -1],
[10, 25, 50, 'All']
]
});

in my angular metronic template i declared lenghtMenu but it doesnt work



Hi Giacomo Cardillo

Could you please check the console log for any error messages? If there are any errors.

Thank you



Hi there aren't any error messages in the console


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
buy metronic keenthemes mega bundle

ReUI

Open-source React components, blocks and templates built on shadcn/ui and Tailwind CSS by Keenthemes.