Reputation: 1987
I'm having problems with the jquery.jtable.js plugin.
My problem:
jTable continues to post this empty modal error message:
For your information:
This is my HTML:
<!-- in the header -->
<script src="~/Scripts/jquery-1.9.1.js"></script>
<link href="~/Content/themes/base/jquery-ui.css" rel="stylesheet" />
<link href="~/Scripts/jtable/themes/basic/jtable_basic.min.css" rel="stylesheet" />
<script src="~/Scripts/jtable/external/json2.min.js"></script>
<script src="~/Scripts/jquery-ui-1.9.2.min.js"></script>
<script src="~/Scripts/jtable/jquery.jtable.min.js"></script>
<!-- in body -->
<div id="UsersTableContainer"></div>
I have this javascript (whithin a $(document).ready()):
$('#UsersTableContainer').jtable({
title: 'All users',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'UserName ASC',
actions: {
listAction: '/api/backend/users/list',
},
fields: {
UserName: {
title: 'UserName',
key: true,
list: true,
width: '20%',
sorting: true
}/* and more
I've tried userName and UserName - nothing works
I've tried to map all properties and none, using a test column - nothing works */
}
});
$('#UsersTableContainer').jtable('load');
I can see with fiddler 2 that this is sent across the line:
{
"records": [
{
"userName": "user"
/*, more properties */
}/*, more records */
],
"result": "OK",
"message": "All OK", //tried with an without this, just to see if it pups up
"totalRecordCount": 2
}
Similar questions:
Upvotes: 2
Views: 2003
Reputation: 21
I suggest you to solve in this way (this is listAction property of jTable plugin):
listAction: function (postData, jtParams) {
console.log("Loading from custom function...");
return $.Deferred(function ($dfd) {
$.ajax({
url: '/api/backend/users/list',
type: 'POST',
dataType: 'json',
data: {},
success: function (data) {
data.Records = data.records;
data.Result = data.result;
data.TotalRecordCount = data.totalRecordCount
delete data.result;
delete data.records;
delete data.totalRecordCount;
$dfd.resolve(data);
},
error: function () {
$dfd.reject();
}
});
});
},
},
Upvotes: 0
Reputation: 43
I was having this same problem and found out, that in my case, I had changed the result from OK to SUCCESS and jTable was checking for OK. Upon further investigation I also found out that jTable is expecting the result property to be capitalized (i.e. Result). I didn't check, but I would guess that Records needs to be capitalized as does TotalRecordCount and Message. I hope this tidbit will help someone else.
Upvotes: 1