Option value not get saved in the database

The option value is not being saved in the database because, as you could see below, the registered option name is num_of_columns and not num_of_cols:

// The second parameter is the option name.
register_setting( 'purchase-history-grid', 'num_of_columns' );

So make sure that you use the correct option name in your settings field callback:

  • Use get_option( 'num_of_columns' ) when retrieving the saved option, and

  • Use name="num_of_columns" in the <input>