Enable delete row functionality in a table

Posted by: iamayush.26 on 30 September 2017, 12:16 am EST

    • Post Options:
    • Link

    Posted 30 September 2017, 12:16 am EST

    Hi,

    I want to add checkbox column in the grid at last to allow user to select the row, which he wants to delete.

    As a column header I want “Select All” Checkbox which select all the checkbox shown on same page to allow user to delete.

    I’ll have a delete button, clicking on which the selected row should be deleted.

    Please guide me through the solution !!

  • Posted 2 October 2017, 10:38 pm EST

    Hello,

    You can create a custom celltype that you add a client side event to the checkbox (like onclick). Then you can catch this client side and look at the event.srcElement.id to find which checkbox was clicked and do your code client side to set the True value to all the cells in that

    column.

    Please have a look at the sample that depicts the same, kindly have a look at it. Hope it will help you.

    https://www.dropbox.com/s/0hrdn7gbbxfngo7/HeaderCheckBox.zip?dl=0&m=

    Please let me know if you have any queries further.

    Thanks,

    Reeva

  • Posted 3 October 2017, 5:29 pm EST

    Hi,

    I got the checkbox in the rows but, when i am trying to add the button “DELETE” in the header row using following line of code, it is not getting added and I am getting blank cell

    sprdPlan.ActiveSheetView.Cells[0, 50].CellType = new FarPoint.Web.Spread.ButtonCellType();

    where 0 is 0th row and 50 is the last column for the grid.

    Can you please help me in getting the button or either we can have a image instead of button.

    Also, Please help me in getting a event fired on click of the button, to check the selected rows and delete it from the grid.

    Regards,

    Ayush

  • Posted 4 October 2017, 4:36 pm EST

    Hi ,

    I am using below code to add checkbox/button to the column header. But unable to see any thing in the header. However If I am giving Text , i could see it in the header.

    But My requirement is to either have checkbox or button in the header.

    Can you please help ???

    Please find my code below used for the same.

    FarPoint.Web.Spread.CheckBoxCellType ckbxcell = new FarPoint.Web.Spread.CheckBoxCellType();

    sprdPlan.ActiveSheetView.ColumnHeader.Cells[0, 50, 1, 50].RowSpan = 2;

    sprdPlan.ActiveSheetView.ColumnHeader.Cells[0, 50].CellType = ckbxcell;

    //sprdPlan.ActiveSheetView.ColumnHeader.Cells[0, 50].Text= “DELETE”;

  • Posted 5 October 2017, 6:19 pm EST

    Hello,

    This is the code you can use to create a CheckBox in header and also to respond it’s click event:

    
    [Serializable()]
        public class myCheck : FarPoint.Web.Spread.CheckBoxCellType
        {
            public override System.Web.UI.Control PaintCell(string id, System.Web.UI.WebControls.TableCell parent, FarPoint.Web.Spread.Appearance style, FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)
            {
                Control c = base.PaintCell(id, parent, style, margin, value, upperLevel);
                CheckBox chk = (CheckBox)c.Controls[0];
                chk.Attributes.Add("onclick", "myCheckFunction()");
                return c;
            }
        }
    
     protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                   
                    myCheck c1 = new myCheck();
                    FpSpread1.ActiveSheetView.ColumnHeader.Cells[0, 0].CellType = c1;
                    for(int i =0;i<FpSpread1.ActiveSheetView.RowCount;i++)
                    FpSpread1.ActiveSheetView.Cells[i, 0].CellType = c1;
                }
            }
    
    

    Client side code to handle Header click:

    
     <script language="javascript" type="text/javascript">
            function myCheckFunction() {
                var spread = document.getElementById("FpSpread1");
                var index = event.srcElement.id.toString();
                var value = event.srcElement.checked;
                var splitstr = index.split(",");
                var rows = spread.GetRowCount();
                if (splitstr[2] == "ch") {
                    for (var i = 0; i < rows; i++) {
                        spread.SetValue(i, splitstr[1], value);
                    
                }
    
                }
            }
        </script>
    
    

    Please refer to the attached sample.

    Thanks,

    Deepak Sharma

    SpreadASPHeaderCheckbox.zip

  • Posted 9 October 2017, 1:34 am EST

    Hi,

    I have used the same approach as mentioned above. But still unable to get the checkbox in header line, but could get the checkbox in other rows with out any issue.

    However if i used text in header, it is shown, but any other cell type is not shown.

    I am using XML File in the design string which defines other headers.

    My Requirement is : upon clicking on search button, the grid view should be populated and displayed and checkbox column should be the last column of grid.

    Can you please help, and let me know, what mistake am I doing in the below mentioned code:

    Is there something I am missing in the below code ?

    int j = sprdPlan.Columns.Count; //total count of columns

    sprdPlan.ActiveSheetView.AddColumns(j, 1); //adding extra column

    myCheck c1 = new myCheck(); //obj for myCheck Class

    sprdPlan.ActiveSheetView.ColumnHeader.Cells[0, j].CellType= c1; //not Working

    //sprdPlan.ActiveSheetView.ColumnHeader.Cells[0, j].Text = “DELETE”; //working

    for (int i = 0; i < sprdPlan.ActiveSheetView.RowCount; i++)

    sprdPlan.ActiveSheetView.Cells[i, j ].CellType = c1;

    [Serializable()]

    public class myCheck : FarPoint.Web.Spread.CheckBoxCellType

    {

    public override System.Web.UI.Control PaintCell(string id,

    System.Web.UI.WebControls.TableCell parent, FarPoint.Web.Spread.Appearance style,

    FarPoint.Web.Spread.Inset margin, object value, bool upperLevel)

    {

    Control c = base.PaintCell(id, parent, style, margin, value, upperLevel);

    CheckBox chk = (CheckBox)c.Controls[0];

    chk.Attributes.Add(“onclick”, “myCheckFunction()”);

    return c;

    }

    }

  • Posted 9 October 2017, 5:59 pm EST

    Hello,

    It looks that the issue is caused by the XML design string you are using in you code. Please test the code without setting the design string and let me know if you are still facing any issues.

    Thanks,

    Deepak Sharma

  • Posted 10 October 2017, 12:52 am EST

    Hi Deepak,

    The issue still persist even after removing the XML design string :frowning:

    Is there any other workaround which I can try and test ?

    Your help is highly appreciated.

    Regards,

    Ayush Jain

  • Posted 11 October 2017, 1:11 am EST

    Hello Ayush,

    Could you please modify the sample application which provided to you in my earlier post and send it back to me after making changes? So that I can replicate the issue at my end and debug it further.

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels