Limit number of rows in the table

Limit number of rows in the table

impex09impex09 Posts: 45Questions: 20Answers: 0

Hi guys, I need to create a condition or simply limitation when in my table has 10 records,
the idea is only allow 10 records no more.
do you have any idea?

thank you.

This question has an accepted answers - jump to answer

Answers

  • haliorishalioris Posts: 9Questions: 2Answers: 0

    That's pretty tough to answer without knowing what your data source is and no code sample. I'd check out this link which may be helpful, otherwise please post the example following the guidelines here for how to ask for help.

  • impex09impex09 Posts: 45Questions: 20Answers: 0
    edited February 2020

    thank you haloris,
    The idea is using datatables,
    When you have 10 records in the table, the application must disable the "New" button.

    select: true,
            lengthChange: false,
            buttons: [
                { extend: 'create', editor: editor, text: 'Crear Nuevo Tutor' },
                { extend: 'edit',   editor: editor, text: 'Modificar Tutor'},
                { extend: 'remove', editor: editor, text: 'Eliminar Tutor' },
                      {
            text: 'Tutores Activos',
            titleAttr: 'Filtrar por Tutores Activos',
            action: function ( e, dt, node, config ) {
              var text = this.text();
              var search = '';
              
              if (text === 'Tutores Activos') {
                this.text('Tutores No Activos');
                this.node().attr('title', 'Tutores Activos');
                search = '1';
              }
              else if (text === 'Tutores No Activos') {
                this.text('Todos');
                this.node().attr('title', 'Activos');            
                search = '0';
              }
              else {
                this.text('Tutores Activos');
                this.node().attr('title', 'Todos');            
                search = '';
              }
              
              table.column(9)
                        .search(search)
                        .draw();
                
            }
          }
    

    Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    edited February 2020 Answer ✓

    You can disable the create button whenever the table is drawn - see example here.

    Colin

  • impex09impex09 Posts: 45Questions: 20Answers: 0

    Excellent! thank you for you support.

This discussion has been closed.