Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
Get multiple value that selected from Datatable Jquery

I have some issues in getting values from datatable that i imported from excel.

i Want to pass the rows that selected (at least can be viewed in alert), here's the case.

the value that i want is like

Name : A. Mused , No HP : 087.... Name : Aida Bugg, No HP : 089.... Name : Allie Grater, No HP : 087...

but the result is just like this screenshot : result popup alert and data

here's the code :

html

 @if (Model != null)
    {
        <table id="tablePenerima" class="table table-striped table-bordered animate__animated animate__fadeInRight" cellpadding="0" cellspacing="0">
            <thead>
                <tr>
                    
                    @foreach (DataColumn col in Model.Tables[0].Columns)
                    {

                        <th align="center">@col.ColumnName</th>
                    }
                </tr>
            </thead>
            <tbody>
                @foreach (DataRow row in Model.Tables[0].Rows)
                {
                    <tr >
                       
                        @foreach (DataColumn col in Model.Tables[0].Columns)
                        {

                            <td align="center">@row[col.ColumnName]</td>
                        }

                    </tr>
                }
            </tbody>
        </table>
    }

and the javascript :

 $(document).ready(function () {
        var table = $('#tablePenerima').DataTable({
            dom: 'Bfrtip',
            buttons: [
               
                'selectAll',
                'selectNone',
                
            ],
            select: true
        });

        $('#tablePenerima tbody').on('click', 'tr', function () {
            $(this).toggleClass('selected');
        });

        $('#btnBlast').click(function () {
            var ids = $.map(table.rows('.selected').data(), function (item) {
                return item[0]
            });
            var data = $('#tablePenerima').DataTable().row('.selected').ids();
            console.log(ids);
            alert("Name:" + ids[0] + "\nNo HP:" + ids[2]);

           });
    });

I hope all of you can solve my problem because my knowledge in js is still weak. Thanks :)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I have no experience with DataTable package, but i think the problem is your map function. It returns the first row of selected rows.

var ids = $.map(table.rows('.selected').data(), function (item) {
                return item[0]
            });

Instead of

return item[0]

You should return all selected rows;

return item

In $('#btnBlast').click event

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda