Checkbox not set to selected when using the command parameter

Checkbox not set to selected when using the command parameter

vjsamvjsam Posts: 10Questions: 2Answers: 0

Hi,

Am trying to adding a checkbox column to an exisitng datatable. has achieved the paging and the checkbox value retaining too when i navigate the pages. But the initial selected checkbox are not shown in UI on the first page which is loaded. When i come back navigate from second page to first page , the checkbox are showing as i have the logic for that in the ajax call. Please find the code below and let me know if you have any idea .

HTML code

'''
<td><input type="checkbox" data-bind="checked:parameter.WorkingItem.IsSelected(), command: $parent.suggestedToStockCheckedChangedCommand, commandParameter: {'WorkingItem': $data, 'SelectedItems': $parent.selectedModels}" /></td>
<td><a class="btn-link" data-bind="text: MaterialNumber, command: $parent.openPartDetailCommand, commandParameter: {'materialNumber': MaterialNumber, 'sectionCallout': SectionCallOut}"></a></td>
<td data-bind="text: Description"></td>
<td data-bind="text: Status"></td>

'''
Checkbox selected change code below

'''
define(["commands/CommandBase"], function (CommandBase) {
function CheckboxCheckedChangedCommand(viewModel, dialogContainerId) {
self = viewModel;
CommandBase.call(this, viewModel);
}
var self = null;
CheckboxCheckedChangedCommand.prototype = new CommandBase;
CheckboxCheckedChangedCommand.prototype.constructor = CheckboxCheckedChangedCommand;

CheckboxCheckedChangedCommand.prototype.execute = function (parameter) {
    if (parameter != undefined || parameter != null) {

        var workingItem = parameter.WorkingItem;
        var selectedItems = parameter.SelectedItems();


        var match = ko.utils.arrayFirst(selectedItems, function (i) {
            if(i.Id != undefined)
                return i.Id() === workingItem.Id();              
            else
                return i.$id() === workingItem.$id();    
        });

        if (workingItem.IsSelected()) {
            if (!match) {
                parameter.SelectedItems.push(workingItem);          
                parameter.WorkingItem.IsSelected(ko.observable(true));
            }
        }
        else {
            if (match) {
                parameter.SelectedItems.remove(match);
            }
        }

    }
};

return CheckboxCheckedChangedCommand;

});
'''

Thanks
vj

This discussion has been closed.