Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: How to append checkbox to each row in table?

I've this for append elements from json:

$.ajax({
                type: "POST",
                url: action,
                data: dataSearch,
                success: function (response) {

                    if (response[0].success == "success") {
                        $.each(response, function (index, record) {
                            var row = $("<tr />");
                            $("<td />").text(record.clavemat).appendTo(row);
                            $("<td />").text(record.tipomat).appendTo(row);
                            $("<td />").text(record.titulomat).appendTo(row);
                            $("<td />").text(record.autormat).appendTo(row);
                            $("<td />").text(record.editmat).appendTo(row);
                            $("<td />").text(record.edicmat).appendTo(row);
                            //Append checkbox to each row
                            row.addClass("alt");
                            row.appendTo(".resultsSearch");
                        });
                    } else {
                        alert("Data not found");
                    }

                }
            });
            return false;

And I want append checkbox for each row at last column, and I dont know Thanks!

like image 691
SoldierCorp Avatar asked Dec 28 '22 00:12

SoldierCorp


1 Answers

Have you tried?:

$("<td />").html('<input type="checkbox"/>').appendTo(row);

And by the way, are you sure that POST is the best choice if you are GETing information from the server? or are you changing the status of the server when you do the request? If it is not the case, check When to use Post or Get

like image 69
Mario Corchero Avatar answered Jan 14 '23 01:01

Mario Corchero