<script type="text/javascript">
	

	$(document).ready(function(){
		loadData()
	})


	
	function loadData() {
		$('#datatable').DataTable({
			"pageLength": 10,
			"serverSide": true,
			"processing": true,
			"scrollX": true,
			"order": [
				[0, "desc"]
			],
			"columnDefs": [
				{
					targets: [0,1,5,6],
					className: "text-center"
				},
				{
					targets: [3,4],
					className: "text-end"
				},
				{
					orderable: false,
					targets: [1,2,6]
				},
				{
					width: '5%',
					targets: [0]
				},
				{
					width: '10%',
					targets: [1]
				},
				{
					width: '25%',
					targets: [2]
				},
				{
					width: '15%',
					targets: [3]
				},
				{
					width: '15%',
					targets: [4]
				},
				{
					width: '10%',
					targets: [5]
				},
				{
					width: '20%',
					targets: [5]
				}
			],
			"ajax": {
				url: baseUrl + 'good/get-all-data',
				type: 'POST',
				data: {
				},
			},
			"columns": [{
					data: "no"
				},
				{
					data: "image"
				},
				{
					data: "name"
				},
				{
					data: "price_buy"
				},
				{
					data: "price_sale"
				},
				{
					data: "stock"
				},
				{
					data: "option"
				},
			],
			"destroy": true
		}); // End of DataTable
	}



	$("#btn_add").on('click',function(e){
		e.preventDefault()
		
		$("#modal_add").modal('show')
		// loading
		$("#modal_add").find('.modal-content').load(baseUrl+'good/add')
	})

	$("#datatable").delegate(".datatable-edit", "click", function (e) {
		  var url = $(this).attr("data-link");
		  e.preventDefault()
			
			$("#modal_edit").modal('show')
			// loading
			$("#modal_edit").find('.modal-content').load(url)


	})


	$("#datatable").delegate(".datatable-detail", "click", function (e) {
		  var url = $(this).attr("data-link");
		  e.preventDefault()
			
			$("#modal_detail").modal('show')
			// loading
			$("#modal_detail").find('.modal-content').load(url)

	})


	

</script>