read a list of values from an input element and sent it to server
read a list of values from an input element and sent it to server
Hi,
I'm using data table editor with sql database and .net framework.
I need to send list of ids to server and load related rows on my data table. my code reads from an input text and a button send my request to server.
My code works and table shows related rows. but after a second table is refreshed and shows all rows again.
In the code, I mapped columns data to my sql columns. I'm not sure which part of code is refreshing data table.
I need to show an empty data table first and then fill it with rows I received from the server.
That would be great if you help me to fix it.
Thanks,
Here is my js code:
(function ($) {
$(document).ready(function () {
var editor = new $.fn.dataTable.Editor({
ajax: '/api/tblorderstatus',
table: '#tblorderstatus',
fields: [
{
label: "Order Status:",
name: "tblorderstatus.status",
type: "select",
options: [
{ label: "Option1", value: "Option1" },
{ label: "Option2", value: "Option2" },
{ label: "Option3", value: "Option3" },
]
}
]
});
var table = $('#tblorderstatus').DataTable({
responsive: true,
"ordering": false,
ajax: '/api/tblorderstatus',
columns: [
{ data: "tblorder.business" },
{ data: "tblorder.name" },
{ data: "tblorder.orderid" },
{ data: "tblorderstatus.status" }
],
select: true,
lengthChange: false
});
$('#orderIdButton').on('keyup click', function () {
table.search($('#OrderIdText').val()).draw();
});
new $.fn.dataTable.Buttons(table, [
{ extend: "edit", editor: editor },
{ extend: "remove", editor: editor }
]);
table.buttons().container()
.appendTo($('.col-md-6:eq(0)', table.table().container()));
});
}(jQuery));
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Replies
Me neither! I don't see anything in the above code that would be doing that. Can you give me a link to the page so I can debug it please?
Sounds like you need to have a condition in your server-side script that will check to see if any ids are submitted. If so, fine, filer on them. If not, then return an empty data set.
Allan
Hi Allan,
As you recommended, I added a parameter in where clause in server side but it didn't work. I believe if I add where to my left join, table refreshing will also be fixed.
Here is my controller:
Use
@orderid
rather than:orderid
.But also I don't see
orderIdText
being submitted in your Javascript above, but that's only part of the JS you are using (I presume) which is why I asked if it would be possible to see your page. If that isn't possible can you show me your full JS file please.Allan
Hi Allan,
I replaced : with @ but didn't work. There is some syntax errors that I can't fix.
Sorry Its not possible to share the whole page here. I just work on part of it.
Here is my full JS. The only Think I need to do is sending OrderIdText value to server and update data table withreturn rows. with this code it works:
but the problem is page refreshes again with all rows.
I need to add condition for loading databale.
if
orderIdText is empty display: "No rows available"
else
display returned rows from the server
This scenario is exactly like search text box functionality but I don't know how to code it for my input element.
Any help is greatly appreciated.
Try:
The MDN documentation has a good description of
Event.preventDefault()
.Allan