Why won't my page read and write check box values to my database.
Why won't my page read and write check box values to my database.
StanR
Posts: 63Questions: 11Answers: 1
My page reads a lot of data from my database when I bring it up. But it doesn't read and write the values of my check boxes. (This worked at one time.) Does anyone see an error in this code?
var editor; // use a global for the submit and return data rendering in the examples
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajax": "../php/checkbox.php",
"table": "#example",
"fields": [ {
label: "Active:",
name: "active",
type: "checkbox",
separator: "|",
options: [
{ label: '', value: 1 }
]
}, {
label: "Category:",
name: "category"
}, {
label: "Test:",
name: "test"
}, {
label: "Automated:",
name: "automated"
}, {
label: "Request/Response:",
name: "request_response"
}
]
} );
$('#example').DataTable( {
order:[],
dom: "Bfrtip",
ajax: "../php/checkbox.php",
columns: [
{ data: "category" },
{ data: "test" },
{ data: "automated" },
{ data: "request_response" },
/* { data: "explanation" }, */
{
data: "active",
render: function ( data, type, row ) {
if ( type === 'display' ) {
return '<input type="checkbox" class="editor-active">';
}
return data;
},
className: "dt-body-center"
}
],
select: {
style: 'os',
selector: 'td:not(:last-child)' // no row selection on last column
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
rowCallback: function ( row, data ) {
// Set the checked state of the checkbox in the table
$('input.editor-active', row).prop( 'checked', data.active == 1 );
}
} );
$('#example').on( 'change', 'input.editor-active', function () {
editor
.edit( $(this).closest('tr'), false )
.set( 'active', $(this).prop( 'checked' ) ? 1 : 0 )
.submit();
} );
} );
</script>
</head>
<body>
<h1>Editor example <span>Always shown checkbox</span></h1>
<table id="example" class="display" style="width:100%">
<thead>
<tr>
<th>Category</th>
<th>Test</th>
<th>Automated</th>
<th>Request/Response</th>
<!-- <th>Explanation</th> -->
<th>Active</th>
</tr>
</thead>
</table>
</body>
</html>
This discussion has been closed.
Replies
Sorry. I put in the wrong page
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
<title>DataTables example - Child rows (show extra / detailed information)</title>
<link rel="shortcut icon" type="image/png" href="/media/images/favicon.png">
<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="http://www.datatables.net/rss.xml">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.5.4/css/buttons.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.7/css/select.dataTables.min.css">
<link rel="stylesheet" type="text/css" href="../../css/editor.dataTables.min.css">
<style type="text/css" class="init">
body {font-family: Arial;}
td.details-control {
background: url('../resources/details_open.png') no-repeat center center;
cursor: pointer;
}
tr.shown td.details-control {
background: url('../resources/details_close.png') no-repeat center center;
}
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/buttons/1.5.4/js/dataTables.buttons.min.js"></script>
<script type="text/javascript" language="javascript" src="https://cdn.datatables.net/select/1.2.7/js/dataTables.select.min.js"></script>
<script type="text/javascript" language="javascript" src="../../js/dataTables.editor.min.js"></script>
<script type="text/javascript" class="init">
/* Formatting function for row details - modify as you need */
function format ( d ) {
console.log(d);
//
d
is the original data object for the rowreturn '
';
}
var editor;
$(document).ready(function() {
editor = new $.fn.dataTable.Editor( {
"ajax": "../php/checkbox.php",
"table": "#example",
"fields": [ {
label: "Active:",
name: "active",
type: "checkbox",
separator: "|",
options: [
{ label: '', value: 1 }
]
}, {
label: "Category:",
name: "category"
}, {
label: "Test:",
name: "test"
}, {
label: "Automated:",
name: "automated"
}
]
} );
/* { "data": "explanation" },
{ "data": "groovydoc" },
{ "data": "source_code" },
{ "data": "use_case" }, */
{
data: "active",
render: function ( data, type, row ) {
if ( type === 'display' ) {
return '<input type="checkbox" class="editor-active">';
}
return data;
},
className: "dt-body-center"
}
],
select: {
style: 'os',
selector: 'td:not(:last-child)' // no row selection on last column
},
buttons: [
{ extend: "create", editor: editor },
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
],
rowCallback: function ( row, data ) {
// Set the checked state of the checkbox in the table
$('input.editor-active', row).prop( 'checked', data.active == 1 );
},
"order": []
} );
} );
</head>
<body class="wide comments example">
</body>
</html>
Was using Chrome. With IE, I can read check-box values, but not write them.
I apologize. I had a cut-and-paste error.
Left out the lines:
Hi @StanR ,
There's a lot going on there, and a lot of updates! When you say it worked at one time, but not now, what changed? Also, how doesn't it work - does it give an error on the client, or server? Would you be able to link to the page, or create a test case that would demonstrate the problem?
Cheers,
Colin
Colin, I didn't make it clear in my last message that this problem is fixed. I had left out several lines inadverently:(
Ah gotcha, I thought that was meant for me, you'd left out the lines for us Glad all fixed!