Recently, studies have shown that the alpha band (8-13 Hz) EEG signals enable the decoding of auditory spatial attention. However, deep learning methods typically requires a large amount of training data. Inspired by sparse coding in cortical neurons, we propose a spiking neural network model for auditory spatial attention detection. The model is composed of three neural layers, two of them are spiking neurons. We formulate a new learning rule that is based on firing rate of pre synaptic and post-synaptic neurons in the first layer and the second layer of spiking neurons. The third layer consists of 10 spiking neurons that the pattern of their firing rate after training is used in test phase of the method. The proposed method extracts the patterns of recorded EEG of leftward and rightward attention, independently, and uses them to train network to detect the auditory spatial attention. In addition, a computational approach is presented to find the best single-trial EEG data as training samples of leftward and rightward attention EEG. In this model, the role of using low connectivity rate of the layers and specific range of learning parameters in sparse coding is studied. Importantly, unlike most prior model, our method requires 10% of EEG data as training data and has shown 90% accuracy in average. This study suggests new insights into the role of sparse coding in both biological networks and brain-inspired machine learning.