Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!