|
How to perform ajax on Data-table once I click on the check-box.
I already have the ability to auto post-back once the checkbox is clicked, I'm not sure how to achieve this.
View:
<script>
$(document).ready(function () {
$("#DashboardTable").DataTable({
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"pageLength": 5,
"ajax": {
"url": "/Chargeback/Index",
"type": "GET",
"datatype": "json"
},
"columnDefs":
[{
"targets": [0],
"visible": false,
"searchable": false
},
{
"targets": [7],
"searchable": false,
"orderable": false
},
{
"targets": [8],
"searchable": false,
"orderable": false
},
{
"targets": [9],
"searchable": false,
"orderable": false
}],
"columns": [
{"data":"ChargebackCode"},
{"data":"StatusName"},
{"data":"BusinessUnitName"},
{"data":"InvoiceCode"},
{"data":"OrderCode"},
{"data":"PickTicketCode"},
{"data":"CustomerPo"},
{"data":"AssignedDepartment"},
{"data":"DivisionName"},
{"data":"Customer"},
{"data":"WarehouseName"},
{"data":"Coordinator"},
{"data":"ChargebackDate"},
{"data":"ModDate"},
{"data":"ChargebackDeadline"},
{"data":"ChargebackCloseDate"},
{"data":" DaysOpen"},
{"data":"ChargebackAmount"},
{"data":"ChargebackBalance"},
{"data":"FaultName"},
{"data":"ResponsibleName"}
]
});
});
</script>
@using (Html.BeginForm("Index", "Chargeback"))
{
<label id = "Include" > @Html.CheckBox("IncludeClosed", (bool)ViewBag.IncludeClosed, new { onChange = "this.form.submit()" }) Include Closed</label>
<table id="DashboardTable" class="table table-striped" >
<thead>
<tr>
<th>Code</th>
<th>Status</th>
<th>Business</th>
<th>Invoice</th>
<th>Order</th>
<th>Pick Tickets</th>
<th>Customer PO</th>
<th>Assigned</th>
<th>Division</th>
<th>Customer</th>
<th>Warehouse</th>
<th>Coordinator</th>
<th>Open Date</th>
<th>Last Activity</th>
<th>Deadline</th>
<th>Closed Date</th>
<th>Days Open</th>
<th>Amount</th>
<th>Balance</th>
<th>Fault</th>
<th>Responsible</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
var chargebackDeadline = item.ChargebackDeadline == null ? "" : ((DateTime)item.ChargebackDeadline).ToString("MM/dd/yyyy");
var chargebackCloseDateAsString = item.ChargebackCloseDate == null ? "" : ((DateTime)item.ChargebackCloseDate).ToString("MM/dd/yyyy");
<tr>
<td>@Html.ActionLink(item.ChargebackCode, "Details", "Chargeback", new { id = item.Id }, null)</td>
<td>@item.StatusName</td>
<td>@item.BusinessUnitName</td>
<td>@item.InvoiceCode</td>
<td>@item.OrderCode</td>
<td>@item.PickTicketCode</td>
<td>@item.CustomerPo</td>
<td>@item.AssignedDepartment</td>
<td>@item.DivisionName</td>
<td>@item.Customer</td>
<td>@item.WarehouseName</td>
<td>@item.Coordinator</td>
<td>@item.ChargebackDate.ToString("MM/dd/yyyy")</td>
<td>@item.ModDate.ToString("MM/dd/yyyy")</td>
<td>@chargebackDeadline</td>
<td>@chargebackCloseDateAsString</td>
<td>@item.DaysOpen</td>
<td>$@item.ChargebackAmount</td>
<td>$@item.ChargebackBalance</td>
<td>@item.FaultName</td>
<td>@item.ResponsibleName</td>
</tr>
}
</tbody>
</table>
}
|
|
|
|
|
I don't understand the question. You have code that initializes your datatable when the page loads. Are you asking how to re-load it when you check a checkbox?
If so,
var table = $('#grdTable').DataTable();
table.ajax.reload();
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
|
Should I remove this portion:
$(document).ready(function () {
and just add this portion:
var table = $('#grdTable').DataTable();
table.ajax.reload();
|
|
|
|
|
No, that first part initializes your table. The second part just tells it to refresh.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
So basically this, This is in my .js file I would link this to my view in mvc:
var table = $('#DashboardTable').DataTable;
table.ajax.reload();
$(document).ready(function () {
$("#DashboardTable").DataTable({
"processing": true,
"serverSide": true,
"filter": true,
"orderMulti": false,
"pageLength": 5,
"ajax": {
"url": "/Chargeback/Index",
"type": "GET",
"datatype": "json"
},
"columnDefs":
[{
"targets": [0],
"visible": false,
"searchable": false
},
{
"targets": [7],
"searchable": false,
"orderable": false
},
{
"targets": [8],
"searchable": false,
"orderable": false
},
{
"targets": [9],
"searchable": false,
"orderable": false
}],
"columns": [
{ "data": "ChargebackCode" },
{ "data": "StatusName" },
{ "data": "BusinessUnitName" },
{ "data": "InvoiceCode" },
{ "data": "OrderCode" },
{ "data": "PickTicketCode" },
{ "data": "CustomerPo" },
{ "data": "AssignedDepartment" },
{ "data": "DivisionName" },
{ "data": "Customer" },
{ "data": "WarehouseName" },
{ "data": "Coordinator" },
{ "data": "ChargebackDate" },
{ "data": "ModDate" },
{ "data": "ChargebackDeadline" },
{ "data": "ChargebackCloseDate" },
{ "data": " DaysOpen" },
{ "data": "ChargebackAmount" },
{ "data": "ChargebackBalance" },
{ "data": "FaultName" },
{ "data": "ResponsibleName" }
]
});
});
modified 8-Jul-19 15:39pm.
|
|
|
|
|
No, you want the reload code in a function, then when you click the checkbox you call that function.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Can you provide a example of what you mean?
|
|
|
|
|
KGr28 wrote: Can you provide a example of what you mean? It is very, very, basic JavaScript. You can copy and paste from what I give you as an example but you need to understand how it works.
fucntion ReloadTable(){
}
Then, if you don't know how, google how to run javascript when checking a box.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
Sorry I am new to javascript hence all of the questions, just trying to get a clear understanding of what exactly you are trying to say.
|
|
|
|
|
I have an ASP.net MVC Web API developed in VS2017 using C# 4.5.2.
I'm trying to deploy it to IIS on a Windows Server 2019 box on the same network by following this article.
- Right Click the project and choose Publish.
- Click New Profile
- Select "IIS,FTP,etc" and click "Create Profile"
- In the Connection dialog, I fill in the server's IP (192.162.50.153), the Site Name, my User Name and Password, and click the "Validate Connection" button.
I get
Could not connect to the remote computer ("192.168.50.153") using the specified process ("Web Management Service") because the server did not respond. Make sure that the process ("Web Management Service") is started on the remote computer. Learn more at: http:
I went to the link in the message.
A. I can Ping the machine
B. The Web Deploy Service is running
C. The port is opened.
What am I doign wrong?? What's the right way to deploy/install my Web API to my server on the same network?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Given we have no access to your network or the machines running on it it is impossible to say why your machine can't connect to the target. If you can't get an IIS deploy working just do a "File" deploy to a folder on your local machine and upload the contents of that folder to the web space for your site on the IIS server.
|
|
|
|
|
I've done a file deploy. I can's access the web API, even locally, which is what led me to the Publish option.
One thing I just found is the logs shows HttpStatus 403 and HttpSubStatus 503. if you look at that here, you'll see that it says "403.503 - Forbidden: the IP address is included in the Deny list of IP Restriction"
I've checked and rechecked, and there are NO restrictions set up.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
Thanks. Already saw that.
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
I am trying to create a checkbox which AutoPostBack when a checkbox is clicked :
ex.
@Html.CheckBox("IncludeClosed", true, new { onChange = "this.form.submit()"})
but i get error:
Uncaught TypeError: Cannot read property 'submit' of null
and If I inspect my code in Developer tools in the browser this is returned:
<input checked="checked" id="IncludeClosed" name="IncludeClosed" onChange="this.form.submit()" type="checkbox" value="true" />input name="IncludeClosed" type="hidden" value="false"
modified 25-Jun-19 14:18pm.
|
|
|
|
|
Is your checkbox definitely inside a <form> tag? If not, then this.form will return null .
The extra hidden input is perfectly normal. The ASP.NET forums have an explanation:
When you submit a form with a checkbox, the value is only posted if the checkbox is checked. So, if you leave the checkbox unchecked then nothing will be sent to the server when in many situations you would want false to be sent instead. As the hidden input has the same name as the checkbox, then if the checkbox is unchecked you'll still get a 'false' sent to the server.
When the checkbox is checked, the ModelBinder will automatically take care of extracting the 'true' from the 'true,false'
If you absolutely want to avoid the extra hidden input you can create your own helper method, as discussed in this StackOverflow thread[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
So I discovered when I updated my CheckBox helper method to :
@Html.CheckBox("IncludeClosed", false, new { onChange = "this.IncludeClosed.submit()"})
This is my form:
@using (Html.BeginForm("Index","Chargeback",FormMethod.Get,new { id = "IncludeClosed"}))
but I get a new error:
Cannot read property 'submit' of undefined
modified 25-Jun-19 15:39pm.
|
|
|
|
|
Javascript doesn't create global variables for elements in your page. If you want to refer to an element by ID, you have to use the document.getElementById method[^].
@Html.CheckBox("IncludeClosed", false, new { onChange = "document.getElementById('IncludeClosed').submit()"})
But if your checkbox is outside of your form, it's not going to be sent back to the server. Only the input elements within the form will be submitted with the form.
You might be able to use the form attribute[^] to work around that. But it's not supported in any version of Internet Explorer or Microsoft Edge. If you need to support either of those browsers, you'll have to move the checkbox inside the form - at which point, your original code will start working.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This approach gives me an error b/c document doesn't exist in the current context also if a submit it as a string then it doesn't recognize the function.
@Html.CheckBox("IncludeClosed", false, new { onChange = "document.getElementById('IncludeClosed').submit()"})
|
|
|
|
|
I figured it out I added the checkbox inside of the form like you suggested and it works:
@using (Html.BeginForm("Index", "Chargeback"))
{
@Html.CheckBox("IncludeClosed", false, new { onChange = "this.form.submit()" })
I am getting the result of true,false but I believe you mentioned how to solve this issue.
Thank you again.
|
|
|
|
|
I'm getting the following warnings when I compile my MVC5 app:
warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Owin.Security.Cookies". Check to make sure the assembly exists on disk.
warning MSB3243: No way to resolve conflicgt between "Microsoft.Owin.Security.Cookies, Version=4.0.1.0, Culture=nuetral, PublicKeyToken=31bf3856ad364e35" and "Microsoft.Owin.Security.Cookies". Choosing "Microsoft.Owin.Security.Cookies, Version=4.0.1.0, Culture=nuetral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
The assembly in question is a nuget package, and it exists in my local nuget repository, and the reference reflects the proper (nuget) path. My web config contains the following:
<dependentAssembly>
<assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
</dependentAssembly>
I'm at a loss. The app compiles with these two warnings, but seems to run fine (since it's evidently selecting the referenced assembly "arbitrarily".
I hate warnings. How do I resolve them?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 26-Jun-19 6:53am.
|
|
|
|
|
My boss wants to start doing this.
I know I can create a new project and specify that I want unit tests, but he also brought up a nuget package called NuGet Gallery|Moq 4.12.0[^^]
Does anyone have any insight in this regard?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Quote: specify that I want unit tests, But the library that your boss brought is more for mocking, rather unit testing. If you don't need to mock the resources such as database connections, network requests, or other and external APIs, then I don't think Moq would be necessary at all a simple xUnit or NUnit would be suitable enough.
Quote: I know I can create a new project And then bring the entire code base in that new project? Doesn't seem legit, but you can easily add a new project in the solution, and connect that (new testing) project with your existing web application as a reference (MVC would be a dll). Then using the content from your MVC, you can run tests on them.
This mocking framework would come in handy where you would need to pass in the database connections, or other content that doesn't need to be there in testing environments; thus Moq.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
Afzaal Ahmad Zeeshan wrote: And then bring the entire code base in that new project? Doesn't seem legit, but you can easily add a new project in the solution, and connect that (new testing) project with your existing web application as a reference (MVC would be a dll). Then using the content from your MVC, you can run tests on them.
When you create a MVC project with unit test turned on, it adds another class library project to your solution. Your app is referenced in the test project, but the test project isn't referenced in the class library. I don't know how it all works yet, or even if you can unit test anything other than controllers.
I had installed Moq thru nuget, and it completely screwed up my app. I had to manually remove it because trying to uninstall via nuget threw errors at me. It was a mess...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|