Awadhendra Awadhendra - 4 months ago 208
jQuery Question

Unable to set data-url value using jquery in bootstrap table

I checked your example and it's working on your example but when I tried it in my example then it doesn't work. I don't know where I am doing mistakes. Is I am using old jquery files. I am posting whole html code on here.

HTML CODE

@{
Layout = null;
}


<!DOCTYPE html>
<html>
<head>
<title>Refresh method with new url</title>
<meta charset="utf-8">
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap-table.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/bootstrap-table.js"></script>
</head>
<body>
<div class="container">
<div class="ribbon">
<a href="https://github.com/wenzhixin/bootstrap-table-examples/blob/master/409.html">View Source on GitHub</a>
</div>
<h1>Refresh method with new url(<a href="https://github.com/wenzhixin/bootstrap-table/issues/409">#409</a>).</h1>
<div class="toolbar">
<button id="refresh" class="btn btn-default">Refresh</button>
</div>
<table id="table"
data-toggle="table"
data-toolbar=".toolbar"
data-url='/Report/GetShipments'>
<thead>
<tr>
<th data-field="id">ID</th>
<th data-field="name">Item Name</th>
<th data-field="price">Item Price</th>
</tr>
</thead>
</table>
</div>
<script>
var $table = $('#table');
$(function () {
$('#refresh').click(function () {
$table.bootstrapTable('refresh', {
url: '/Report/ShowShipment'
});
});
});
</script>
</body>
</html>


Controller code.

public class ReportController : Controller
{
// GET: Report
public ActionResult Index()
{
return View();
}

public ActionResult GetShipments()
{
//IShipments shipments = new ShipmentsClient();
//var data = shipments.GetShipments(string.Empty, string.Empty, string.Empty, string.Empty);
//return Json(data, JsonRequestBehavior.AllowGet);

return Json("test" , JsonRequestBehavior.AllowGet);
//return new Json()
}

public ActionResult ShowShipment()
{
//IShipments shipments = new ShipmentsClient();
//var data = shipments.GetShipments(string.Empty, string.Empty, string.Empty, string.Empty);
//return Json(data, JsonRequestBehavior.AllowGet);

return Json("test", JsonRequestBehavior.AllowGet);
//return new Json()
}

public ActionResult Test()
{
return View();
}

}


When page load then it hit GetShipment() method og controller and when we click refresh button then it should hit ShowShipment method but unfortunately it always hot GetShipment() method. I don't know what mistake I am doing.

Thanks,
Awadhendra

Answer

You can use refresh method:

$table.bootstrapTable('refresh', {
    url: 'new url'
});

I have added a example here: http://issues.wenzhixin.net.cn/bootstrap-table/409.html

The documentation: http://bootstrap-table.wenzhixin.net.cn/documentation/#methods

Hope to help you.