How to reset the column value using sql and knockout js in MVC?

If, we assign the rank to the column
Name.   .   .    .   .      . Rank
A.                        .   .   .  1
B                                     2
C                            .   .   . 3

When the user adds the data, the rank is saved in DB(database).

How to update the rank in DB, when user delete the data using knockout?

On click of delete, there is one function called
Remove row
And in that function table row<tr> is removed using knockout.

Example: if we delete row B its order will be, -1 as deleted item will have rank/order -1 and order/rank of c will be 2

Is, there any alternative way to reset the column value in SQL or something else? 

Please, suggest me

Thank you

Asked by:- SnehalSawant
: 3939 At:- 12/17/2017 3:22:52 AM sql knockout-js

1 Answers
profileImage Answered by:- vikas_jk

You should Aajx request to C# controller, with the ID of the row to remove change rank of the item in the database to -1, and decrease the rank of just next row. Suppose You have removed row B with rank 2, then using jQuery Ajax, call C# controller and pass it's Primary Id to the controller, using ADO.NET update it's rank/order value to -1 and decrease rank(from 3 to 2) of just next element(if there is any) like C.

If you don't know how to call Controller fro knockout js take a look at the below code snippet


//Here self is EmployeeViewModel data
// var self = this;

self.delete = function (Employee) {

            if (confirm('Are you sure to Delete "' + Employee.FirstName + '" employee ??')) {

                var id = Employee.EmployeeID;



                    url: '@Url.Action("DeleteEmployee", "Employee")',

                        cache: false,

                        type: 'POST',

                        contentType: 'application/json; charset=utf-8',

                        data: ko.toJSON(id),

                        success: function (data) {


                            //   alert("Record Deleted Successfully");



                     function (xhr, textStatus, err) {




At:- 12/17/2017 3:50:55 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use