WIP: adds first steps to use datatables for mass updates and search / sort

This commit is contained in:
2020-02-08 01:05:48 +01:00
parent d4badf7f9e
commit 796c5516f9
3 changed files with 66 additions and 41 deletions

View File

@@ -1,4 +1,5 @@
@model HomeModel;
@using Microsoft.AspNetCore.Mvc.Routing
@model HomeModel;
@{
ViewData["Title"] = "TV7 Playlist";
}
@@ -116,20 +117,21 @@ $(document).ready(function() {
{
text: 'Disable selected',
action: function ( e, dt, node, config ) {
alert(
'Row data: '+
JSON.stringify( dt.row( { selected: true } ).data() )
);
const ids = $.map(table.rows('.selected').data(), function (item) {
return item[1]
});
setEnabledForChannels(urlDisable, ids);
},
enabled: false
},
{
text: 'Enable selected',
action: function ( e, dt, node, config ) {
const ids = $.map(table.rows('.selected').data(), function (item) {
return item[1]
});
alert(JSON.stringify( ids ));
const ids = $.map(table.rows('.selected').data(), function (item) {
return item[1]
});
setEnabledForChannels(urlEnable, ids);
},
enabled: false
},
@@ -153,6 +155,25 @@ $(document).ready(function() {
table.button( 4 ).enable( selectedRows > 0 );
} );
});
const urlEnable = '@Url.Action("EnableChannels","PlaylistApi")';
const urlDisable = '@Url.Action("DisableChannels","PlaylistApi")';
function setEnabledForChannels(url, ids) {
const options = {};
options.url = url;
options.type = "PUT";
options.data = JSON.stringify(ids);
options.contentType = "application/json";
options.dataType = "html";
options.success = function (msg) {
$("#msg").html(msg);
};
options.error = function () {
$("#msg").html("Error while calling the Web API!");
};
$.ajax(options);
}
</script>
</form>